Javascript 物料界面更改输入';s活性色
如何更改活动输入的颜色?我想更改默认的蓝色,但找不到如何更改 从我尝试过的情况来看,这不是Javascript 物料界面更改输入';s活性色,javascript,reactjs,material-design,material-ui,Javascript,Reactjs,Material Design,Material Ui,如何更改活动输入的颜色?我想更改默认的蓝色,但找不到如何更改 从我尝试过的情况来看,这不是color属性的问题,也不是FormControl、InputLabel或Input中的问题。此外,没有可用的underlineStyleprop() 我只想在输入处于活动状态时将颜色更改为my主题中定义的myprimary颜色,也就是说,用户在其中写入内容 我使用的是Input而不是TextField,因为我想按照使用InputAdornments 编辑 看起来我应该改变。MuiInput-inkbar-
color
属性的问题,也不是FormControl、InputLabel或Input中的问题。此外,没有可用的underlineStyle
prop()
我只想在输入处于活动状态时将颜色更改为my主题中定义的myprimary
颜色,也就是说,用户在其中写入内容
我使用的是Input
而不是TextField
,因为我想按照使用InputAdornments
编辑
看起来我应该改变。MuiInput-inkbar-169:after
的背景色。你建议我怎么做?还有别的办法吗
/* eslint-disable flowtype/require-valid-file-annotation */
import React from 'react';
import { withStyles } from 'material-ui/styles';
import Input, { InputLabel } from 'material-ui/Input';
import { FormControl } from 'material-ui/Form';
const styles = theme => ({
formControl: {
margin: theme.spacing.unit,
width: '100%',
},
textField: {
marginLeft: theme.spacing.unit,
marginRight: theme.spacing.unit,
}
});
class CustomInput extends React.Component {
...
render() {
const { classes, label, id } = this.props;
const error = (this.props.valid === undefined ? false : !this.props.valid) && this.state.visited
return (
<FormControl className={classes.formControl} >
<InputLabel error={error}>{label}</InputLabel>
<Input
id={id}
className={classes.textField}
value={this.state.value || ''}
endAdornment={this.props.endAdornment ?
<InputAdornment position="end">
{this.props.endAdornment}
</InputAdornment> : ''
}
/>
</FormControl>
);
}
}
CustomInput.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(CustomInput);
定义一些类(注意绿色类):
constyles=theme=>({
容器:{
显示:“flex”,
flexWrap:“wrap”,
},
表单控制:{
边距:theme.space.unit,
},
绿色标签:{
颜色:'#0f0',
},
绿色下划线:{
“&:hover:not($disabled):在”:{
背景颜色:“#040”,
},
},
绿色墨水条:{
“&:在”之后:{
背景颜色:“#0f0”,
},
},
});
使用以下命令将它们添加为classes
prop:
导出默认样式(样式)(ComposedTextField);
使用withStyles提供的classes
prop中的类名覆盖组件中使用的类:
render(){
const{classes}=this.props;
返回(
名称
);
在其inkbar和underline类中使用主题的原色,因此我们使用我们定义的greenInkbar和greenUnderline类覆盖它们
对于,它是的包装器,我们必须通过FormControlClasses属性传递类
请看一下这一点,以便进行工作复制。实际上,我对您的回答有一个问题:它工作正常(谢谢!),但控制台中确实有一个警告:警告:[JSS]在CustomInput中找不到禁用的引用规则。
。有什么线索吗?(如果我注释掉我在样式
对象中添加的新类,并注释掉组件中的类
属性,则不会发生此错误)抱歉!在类规则中使用$disabled需要在同一工作表中使用禁用的类。您还需要重写禁用的类。定义禁用的类并重写它,就像使用下划线一样(通过类将其传递给组件)。查看输入中的原始类,您可以复制它:@KenGregory codesandbox示例似乎不再有效
.MuiInput-inkbar-169:after {
background-color: #3f51b5 !important
}