Reputation: 23
i want to change color of no options. can you please help me
<Autocomplete
id="id"
options={options}
limitTags={3}
value={value}
noOptionsText="no options"
getOptionLabel={option => option}
onChange={onChange}
renderInput={params => (
<TextField
{...params}
label=" title"
placeholder="Please select"
/>
)}
/>
Upvotes: 2
Views: 3171
Reputation: 61
In mui v5 there are different approaches
Solution 1 To use themeProvider
import { createTheme, ThemeProvider } from '@mui/material/styles';
const theme = createTheme({
components: {
// Name of the component
MuiAutocomplete: {
styleOverrides: {
// Name of the slot
noOptions: {
// Some CSS
color: "red",
backgroundColor: "pink",
},
},
},
},
});
<ThemeProvider theme={theme}>
<Autocomplete
id="id"
options={options}
limitTags={3}
value={value}
noOptionsText="no options"
getOptionLabel={option => option}
onChange={onChange}
renderInput={params => (
<TextField
{...params}
label=" title"
placeholder="Please select"
/>
)}
/>
</ThemeProvider>
Solution 2
To use css class for noOption prop which is .MuiAutocomplete-noOptions
css file:
.MuiAutocomplete-noOptions {
background-color: pink;
color: red!important;
}
Upvotes: 3
Reputation: 81653
You can use classes
props to apply styles to a specific sub-component of the Autocomplete
component
const useStyles = makeStyles({
noOptions: {
color: "red",
backgroundColor: "pink"
}
});
export default function Demo() {
const styles = useStyles();
return (
<Autocomplete
classes={{
noOptions: styles.noOptions
}}
options={top100Films}
renderInput={(params) => (
<TextField {...params} label="Combo box" variant="outlined" />
)}
/>
);
}
Upvotes: 1