Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
How to customize Material UI autocomplete dropdown menu

I am using Material UI v5 beta1 and I have been trying to customize their Autocomplete component so that the Typography color on the options changes from black to white whenever the item is selected, however, I can't figure out how to pass the style to it. So far I have tried passing my styles on .MuiAutocomplete-option either through a styled component or a global override (see code attached) and tried every state I can think of, hover, selected, focused, even tried the Material classes for those but none of them worked. I have also tried using a custom Popper with a MenuList inside but with no luck. I have been pulling my hair with this for a couple of days now, and not being able to inspect the DOM makes it even harder, any help or tip would be highly appreciated. Thank you in advance.

MuiAutocomplete: {
    styleOverrides: {
        root: {
           // ...
        },
        option: {
            padding: '5px 12px',
            backgroundColor: theme.palette.background.paper,
            display: 'flex',
            height: 42,
            borderRadius: theme.borderRadius.s,

            '&:hover': {
                backgroundColor: theme.palette.action.hover,
                '& .Mui-Typography-root': { color: theme.palette.text.contrast },
            },

            '& .Mui-selected': {
                backgroundColor: theme.palette.action.hover,
                '& .Mui-Typography-root': { color: theme.palette.text.contrast },
            },

            '&.disabled': {
                opacity: 0.5,
                '& .Mui-Typography-root': {
                    color: theme.palette.text.disabled,
                },
            },
        },
renderOption={(props, option) => {
    return (
        <li {...props}>
            <Box display={'flex'} flexDirection={'row'}>
                <Avatar size={'32'} variant={'circular'} />
                <Box display={'flex'} ml={3} flexDirection={'column'}>
                    <Typography color={'text.primary'}>
                        {option.label}
                    </Typography>
                    <Typography color={'text.secondary'}>
                        Extra Information
                    </Typography>
                </Box>
            </Box>
        </li>
    );
}}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I would pass in { selected } to your renderOption, then use it to toggle your styling inline

For example:

renderOption={(props, option, { selected }) => {
    return (
        <li {...props}>
            <Box display={'flex'} flexDirection={'row'} style={{ backgroundColor: selected ? 'red' : 'green' }}>
                <Avatar size={'32'} variant={'circular'} />
                <Box display={'flex'} ml={3} flexDirection={'column'}>
                    <Typography color={'text.primary'}>
                        {option.label}
                    </Typography>
                    <Typography color={'text.secondary'}>
                        Extra Information
                    </Typography>
                </Box>
            </Box>
        </li>
    );
}}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda