admin管理员组文章数量:1289508
you can see in the image below my background color is like gray am text field color is white when I show an error then that text field white color gets extended and the password error shows it's not looking good I need a set like text field white not get extend it error shown below in grey background
<TextField
className={classes.textField}
variant="outlined"
id="outlined-basic"
fullWidth
type={values.hidden ? "password" : "text"}
{...loginForm.getFieldProps("password")}
name="password"
error={loginForm.touched.password && loginForm.errors.password}
helperText={loginForm.touched.password && loginForm.errors.password}
placeholder="Password"
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
className="icon"
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{values.hidden ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
)
}}
/>;
CodeSandBox
you can see in the image below my background color is like gray am text field color is white when I show an error then that text field white color gets extended and the password error shows it's not looking good I need a set like text field white not get extend it error shown below in grey background
<TextField
className={classes.textField}
variant="outlined"
id="outlined-basic"
fullWidth
type={values.hidden ? "password" : "text"}
{...loginForm.getFieldProps("password")}
name="password"
error={loginForm.touched.password && loginForm.errors.password}
helperText={loginForm.touched.password && loginForm.errors.password}
placeholder="Password"
InputProps={{
endAdornment: (
<InputAdornment position="end">
<IconButton
className="icon"
aria-label="toggle password visibility"
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
edge="end"
>
{values.hidden ? <VisibilityOff /> : <Visibility />}
</IconButton>
</InputAdornment>
)
}}
/>;
CodeSandBox
Share Improve this question edited May 19, 2021 at 22:06 asked May 19, 2021 at 17:24 user12302978user123029784 Answers
Reset to default 4You may use the FormHelperTextProps props to set style or class to the helper text props
<TextField
....
FormHelperTextProps={{ style: { backgroundColor: 'transparent' }}}
/>
Also, if setting className does not work for you (since it works on the parent div) you may want to learn how to use classes props or InputProps props of TextField
https://material-ui./api/text-field/
You can change the TextField
error color and other css properties here:
textfield: {
backgroundColor: "#fff",
"& .MuiFormHelperText-root.Mui-error": { //<--- here
backgroundColor: "red",
margin:0,
paddingLeft: 10
},
},
You over overide style of class MuiFormHelperText-root:
import React from "react";
import TextField from "@material-ui/core/TextField";
import { makeStyles } from "@material-ui/core/styles";
import { InputAdornment } from "@material-ui/core";
import PersonIcon from "@material-ui/icons/Person";
const useStyles = makeStyles((theme) => ({
root: {
"& .MuiTextField-root": {
margin: theme.spacing(1),
width: 200
},
"& .MuiFormHelperText-root": {
color: "#000 !important"
}
},
bg: {
backgroundColor: "#7986cb"
},
textfield: {
backgroundColor: "#fff"
}
}));
export default function ValidationTextFields() {
const classes = useStyles();
return (
<form className={classes.root} noValidate autoComplete="off">
<div className={classes.bg}>
<TextField
className={classes.textfield}
placeholder="Email"
variant="outlined"
fullWidth
name="username"
error
helperText={"error!"}
type="text"
id="outlined-basic"
InputProps={{
endAdornment: (
<InputAdornment position="end">
<PersonIcon />
</InputAdornment>
)
}}
/>
</div>
</form>
);
}
This can also achieved in css file
.MuiFormHelperText-root.Mui-error {
opacity: 1;
color: rgba(255, 109, 109, 1);
font-family: 'Open Sans';
font-size: 10px;
font-weight: 600;
font-style: italic;
letter-spacing: 0px;
text-align: left;
/* background-image: url('../../../assets/error.png');
background-repeat: no-repeat;
padding-left: 20px;
padding-top: 2px;*/
}
In jsx file,
<FormHelperText id="ponent-helper-text">
{validEmail ? ' ' : errorMessageEmail}
</FormHelperText>
本文标签: javascriptI need to change material UI helper text backgroundStack Overflow
版权声明:本文标题:javascript - I need to change material UI helper text background - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741473229a2380731.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论