Reputation: 2123
I'm trying to set the hover border color of a TextField to a theme variable. However I found that the hover borderColor needs the "!important" tag to work, but I don't know how to add it to the theme variable?
So basically what I need to do is borderColor: theme.palette.primary.main!important
somehow.
I made an example below, you can also check the codesandbox. Any suggestions are welcome!
const style = {
fieldset: {
borderColor: theme.palette.primary.main
},
"&:hover fieldset": {
//borderColor: "green!important" // works
borderColor: theme.palette.primary.main // doesnt work
}
};
return <TextField sx={style} />;
https://codesandbox.io/s/bold-robinson-17spqs
Upvotes: 2
Views: 1861
Reputation: 709
Two edits:
primary.main
)+ "!important"
to your code.Try following, it works:
import { React } from "react";
import { TextField } from "@mui/material";
export const theme = {
palette: {
primary: {
main: "#D20000",
secondary: "green"
}
}
};
export default function App() {
const style = {
fieldset: {
borderColor: theme.palette.primary.main
},
"&:hover fieldset": {
//borderColor: "green!important" // works
borderColor: theme.palette.primary.secondary + "!important" // doesnt work
}
};
return <TextField sx={style} />;
}
Upvotes: 2