У меня есть это TextField ниже, которое работает по назначению, и я хочу изменить цвет метки, когда он не в фокусе, потому что, когда он в данный момент не в фокусе, он остается черным.
Может ли кто-нибудь помочь мне, как я могу этого достичь?
const useStyles = makeStyles(theme => ({
textField: {
width: "300px"
},
cssLabel: {
color: "white"
},
cssOutlinedInput: {
"&$cssFocused $notchedOutline": {
borderColor: `white !important`
}
},
cssFocused: { color: "white !important" },
notchedOutline: {
borderWidth: "1px",
borderColor: "white !important"
}
}));
<TextField
id = "username"
label = "Username"
className = {classes.textField}
variant = "outlined"
required = {true}
InputLabelProps = {{
classes: {
root: classes.cssLabel,
focused: classes.cssFocused
}
}}
InputProps = {{
classes: {
root: classes.cssOutlinedInput,
focused: classes.cssFocused,
notchedOutline: classes.notchedOutline
}
}}
/>;
@jagsler Да. Когда я пишу, ввод белый, а когда ввод теряет фокус, он снова становится черным





Также установите белый цвет корневых стилей по умолчанию.
const useStyles = makeStyles(theme => ({
textField: {
width: "300px"
},
cssLabel: {
color: "white"
},
cssOutlinedInput: {
color: 'white', // <!-- ADD THIS ONE
"&$cssFocused $notchedOutline": {
borderColor: `white !important`
}
},
cssFocused: { color: "white !important" },
notchedOutline: {
borderWidth: "1px",
borderColor: "white !important"
}
}));
Вы говорите, что он остается черным, но в вашем примере фактическая метка всегда белая, сфокусированная или нет. Под «меткой» вы подразумеваете цвет входного значения?