Search code examples
reactjsautocompletematerial-uistyles

How to apply style on NoOptionsText in autocomplete material-ui


i want to change color of no options. can you please help me

image link

<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"
   />
 )}
/>

Solution

  • 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" />
          )}
        />
      );
    }
    

    Live Demo

    Edit 63949999/how-to-apply-style-on-nooptionstext-in-autocomplete-material-ui/63950742#63950742