简体   繁体   English

如何在不使用的情况下更改Material-UI TextField底部颜色<MuiThemeProvider />

[英]How to change Material-UI TextField bottom color without using <MuiThemeProvider />

I have a Material UI TextField component that is on a dark background, so for just this one component, I'd like to change it so that the text and line colours are all red. 我有一个在深色背景上的Material UI TextField组件,因此对于这个组件,我想对其进行更改,以使文本和线条颜色均为红色。 The rest of the TextField instances should remain unchanged. 其余的TextField实例应保持不变。

I am using @material-ui/core 3.8.1 and it's <TextField /> component. 我正在使用@ material-ui / core 3.8.1 ,它是<TextField />组件。

I want to avoid having to use <MuiThemeProvider> 我想避免不得不使用<MuiThemeProvider>

This is how I have tried based on the recommendation here for the Material-UI <Input /> component and the answer here 这是我根据此处对Material-UI <Input />组件的建议以及此处的答案进行的尝试

Reproduction: https://codesandbox.io/s/q9yj0y74z6 复制: https : //codesandbox.io/s/q9yj0y74z6

Add this props in <TextField /> <TextField />添加此props

InputLabelProps={{
  className: classes.cssLabels
}}

Add in styles 添加styles

cssLabels: {
  color: "red"
}      

If you want to override the Input 's classes, you'll have to use something like this: 如果要覆盖Input的类,则必须使用类似以下的内容:

<TextField
  InputProps={{classes:{underline: classes.underline}}}
  ...
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM