首页 > 解决方案 > 在 ReactJS 中更改 TextField 的线条颜色

问题描述

我正在使用 ReactJS 制作组件。因为我需要用不同的颜色自定义 TextInput 的线条颜色(一种用于成功验证,另一种用于失败验证)

import React, {Component} from 'react';
import {View, Text, StyleSheet, TextInput} from 'react-native';
import TextField from '@material-ui/core/TextField';

export default class CustomTextInput extends Component {
constructor(props) {
super(props);
this.state = {
  name: '',
};
}
render() {
return (
  <View>
    <TextField
      style={{margin: 10}}
      id="standard-basic"
      label="Standard"
      error={false}
      inputProps={{maxlength: 12}}
      label="User Id"
    />
  </View>
);
}

[![success validation][1]][1]

标签: reactjscustom-controls

解决方案


首先,你可以使用material-ui's errorprop. 如果您仍想更改颜色,则应使用material-ui'swithStylesmakeStyles.


推荐阅读