I am having a Search box like this when focusing:
How to change the colour of its background, border and icon of it? And also the way to modify when not focusing.
My code:
<TextField
className={classes.searchBarStyle}
placeholder="Search"
type="search"
margin="normal"
variant="outlined"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<Search />
</InputAdornment>
),
classes: {input: classes.input}
}}
/>
CSS:
searchBarStyle: {
height: "40px",
width: "200px",
margin: "0 0 0 0",
float: "right",
},
input: {
color: "white",
textDecoration: "none",
'&::placeholder': {
color: 'white',
fontWeight: "400"
}
}
Material-UI v5 The easiest way to change the focus color of the TextField is to set the color props which is quite limited because it only accepts these values, (the color can be extended but you need to write a bit of code).
Helper text gives context about a select, such as how the selection will be used. It should be visible either persistently or only on invalid state.
We can use TextField component in Material UI to show input textbox. import TextField from "@material-ui/core/TextField"; When using the TextField component, we can pass the required attribute to mark the component as required.
I've same problem too then I found your question and try to solve it by myself. I think this isn't late to answer.
You can use makeStyles from @material-ui/core/styles for example, I create border-color & border-raduis on default, border-color and border-width in focus and Change icon to
import { makeStyles } from '@material-ui/core/styles';
import { TextField } from '@material-ui/core/TextField';
import PersonAddIcon from '@material-ui/icons/PersonAdd';
const useStyles = makeStyles(theme => ({
searchBarStyle: {
height: "40px",
width: "200px",
margin: "0 0 0 0",
float: "right",
"& .MuiOutlinedInput-root": {
"& fieldset": {
borderRadius: "20px",
borderColor: "#000fff"
},
"&.Mui-focused fieldset": {
borderColor: "#C52328"
borderWidth: "2px"
}
}
}
}))
const CustomTextField = () => {
const classes = useStyles()
return <TextField
className={classes.searchBarStyle}
placeholder="Search"
type="search"
margin="normal"
variant="outlined"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<PersonAddIcon />
</InputAdornment>
)
}}
/>
}
export default CustomTextField;
All of className that I modified can check in Inspect mode in Browser
if you want more information, check this link (Check at Customized Inputs)
TextField React component- Material-UI
I hope this answer can help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With