question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Autocomplete] can't change option highlight color

See original GitHub issue
  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

The Autocomplete component uses a very light default option highlight and doesn’t exposes any CSS props to easily change it as far as i can tell.

Expected Behavior 🤔

an easy css classname/selector exposed to change the highlight color of the options

currently, it’s setting .MuiAutocomplete-option[data-focus="true"] but I can’t figure out how to actually change that using makeStyles or any other documented way

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:20 (6 by maintainers)

github_iconTop GitHub Comments

38reactions
matthlavackacommented, Apr 30, 2020

I’m able to change it by doing:

createStyles({
    listbox: {
      padding: 0,
    },
    option: {
      borderBottom: `1px solid ${theme.palette.system[5]}`,
      // Hover
      '&[data-focus="true"]': {
        backgroundColor: theme.palette.secondSurface.light,
        borderColor: 'transparent',
      },
      // Selected
      '&[aria-selected="true"]': {
        backgroundColor: theme.palette.secondSurface.main,
        borderColor: 'transparent',
      },
    },
  });

<Autocomplete
   classes={{
      option: cs.option,
      listbox: cs.listbox,
   }}
/>
29reactions
jdokloviccommented, Sep 19, 2020

Actually, I found a solution that will work for now. I just needed to do:

const useStyles = makeStyles({
    '@global': {
        '.MuiAutocomplete-option[data-focus="true"]': {
            background: 'blue'
        }
    }

});

and then in my component function, simply call useStyles();

It’s not great, but it will get me through until a “real” solution is found.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Autocomplete] can't change option highlight color #19692
The Autocomplete component uses a very light default option highlight and doesn't exposes any CSS props to easily change it as far as...
Read more >
Change the color of MUI Autocomplete option - Stack Overflow
I have to render option by option with the respective color in option background.
Read more >
Change highlight color Autocomplete Material UI ReactJS
This post explains how to change highlight color for Autocomplete Material UI in ReactJS.
Read more >
A trick to change the autocomplete background-color
What we've done here is simply select the pseudo element Autofill and then apply a huge box shadow inside of it, so the...
Read more >
MUI v5 -> How to style options inside Autocomplete component
I'm just trying to change the background color on hover, and based on whether or not it is selected. I've tried 2 approaches...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found