根据此处的 MUI Texfield API,Textfield 是以下组件之上的简单抽象
- 表单控件
- 输入
- 输入标签
- 填充输入
- 大纲输入
- 输入
- 表单助手文本
因此,要更改上述任何组件的 Textfield 样式,例如 NotchedOutline 类,它是 OutlinedInput 的类,我可以执行以下操作
import { TextField } from '@material-ui/core';
const style = theme => ({
notchOutline: { /*style in here*/ }
});
<TextField
inputProps={{ notchedOutline : classes.notchedOutline }}
>
</TextField>
如果该子组件类仅对于该组件是唯一的,则所有这些都可以实现。
我的问题是,我如何为更常见的命名类设置样式,比如我想一次修改 OutlinedInput、InputLabel、FormHelperText 或 TextField 内的更多子组件的根类?我不认为这会起作用吗?
<TextField
FormControlProps={{ root: classes.root }}
OutlinedInputProps={{ root: classes.root, notchedOutline : classes.notchedOutline }}
>
</TextField>
或者
<TextField
inputProps={{
root: classes.OutlinedInputRoot,
root : classes.FormHelperTextRoot
}}
>
</TextField>
需要关于如何瞄准 TextField 子组件的特定根的帮助,而无需涉及全局 MUI 主题,或者根本不使用提供的 TextField,而是使用这些子组件构建文本字段组件。