Material-ui: [Autocomplete] Label Designs

Created on 8 Jul 2020  路  2Comments  路  Source: mui-org/material-ui

I'm attempting to add some custom styles to the Autocomplete component but can't seem to change the label at all. I feel like I'm missing something. It seems to be different than the standard <TextField /> component. Apologies if this has been addressed somewhere, I haven't been able to find a solution.

Below is what I would normally do with a TextField component. This doesn't work with Autocomplete however...:

    '& .MuiFormLabel-root': {
      color: '#fff'
      }

Current Style with non-working label style change

const useStyles = makeStyles(theme => ({
  inputRoot: {
    color: '#fff',
    '& .MuiSvgIcon-root': {
      color: '#fff'
    },
    '& .MuiOutlinedInput-notchedOutline': {
      borderColor: '#fff'
    },
    '&:hover .MuiOutlinedInput-notchedOutline': {
      borderColor: theme.palette.primary.main
    },
    '&.Mui-focused .MuiOutlinedInput-notchedOutline': {
      borderColor: theme.palette.primary.light
    },
    '& .MuiFormLabel-root': { <=== (Doesnt seem to work)
      color: '#fff'
      }
    },
  }
}))

Autocomplete component

      <Autocomplete
        multiple
        id='tags-outlined'
        classes={{ inputRoot: classes.inputRoot }}
        options={States}
        value={toggleStates || ''}
        getOptionLabel={(option) => option.name}
        defaultValue={toggleStates[0]}
        disableClearable
        filterSelectedOptions
        onChange={(event, newValue) => { handleChangeMiddle(newValue) }}
        renderInput={(params) => (
          <TextField
            {...params}
            variant='outlined'
            placeholder='Select'
            label='States'
          />
        )}
      />
question

All 2 comments

In the future please provide a minimal reproducible example, something like a codesandbox demo will do.

The inputRoot class gets applied to the InputBase (the div wrapping the input). The label is outside this div hence the CSS isn't applied. There are multiple ways you can achieve this: you can apply the inputRoot class to the autocomplete root or directly to the rendered input using className.

Apologies, I'll make sure to add a codesandbox next time. Thank you for your response!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rbozan picture rbozan  路  3Comments

mattmiddlesworth picture mattmiddlesworth  路  3Comments

ryanflorence picture ryanflorence  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments

activatedgeek picture activatedgeek  路  3Comments