Focused Select component shows wrong color in dark theme
See original GitHub issue- This is not a v0.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
In a dark theme, the text of the control should be white and stay that way when the control is focused.
Current Behavior
In Firefox, the text turns black. In Chrome it says white as it should.
Steps to Reproduce
Link: https://codesandbox.io/s/52l1po8nlx
- Click any of the Select drop-downs
- Select a value so the options disappear but the control stays focused
Note that setting a :focus
pseudo class in dev tools is not enough. You have to actually do it.
Context
The style for Select has the following special case for Firefox:
// Remove Firefox focus border
'&:-moz-focusring': {
color: 'transparent',
textShadow: '0 0 0 #000',
},
It’s clear why this includes a color
. Presumably it’s for something to do with the native select, but it gets imported to the simple select as well. transparent
causes the color to be black, which looks fine on a light theme but is wrong on a dark theme. That’s probably why nobody noticed it.
Your Environment
Tech | Version |
---|---|
Material-UI | v3.2.1 |
React | 16.5.2 |
Browser | Firefox v62.0.3 |
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Focused Select component shows wrong color in dark theme
Expected Behavior. In a dark theme, the text of the control should be white and stay that way when the control is focused....
Read more >Material UI Select focus and selected background color
Any tips how to remove or override those background colors? Select component doesn't have to keep it's focus after option is selected. EDIT: ......
Read more >The selection of focus colors has a few issues in the different ...
There are a few issues with the selection of focus colors if you take a look in both modes, the daylight as well...
Read more >Dark mode in React: An in-depth guide - LogRocket Blog
Here we will use the prefers-color-scheme that gives us dark , light , or no-preference based on the device's selected color scheme.
Read more >Applying color to HTML elements using CSS - MDN Web Docs
This article is a primer introducing each of the ways CSS color can be used in HTML.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks @oliviertassinari and @joshwooding!
Okay, I think I have a better idea of what’s going on here. It’s a bit tricky since
:-moz-focusring
is not well documented.It seems that the outline uses the text color, so this hack makes the text color transparent and makes it visible again by putting a black shadow on the text, but with no blur. So it mimics the look of text that’s the original color.
I played around with
currentColor
for the shadow, but that doesn’t work since it just copies the text color from the same style, which is now transparent. The only thing that seems to work is setting the shadow color to the text color from the theme, which is otherwise set here astheme.palette.text.primary
.The only problem with this approach is that if someone changes the text color of the InputBase, they’ll have to do it again in
:-moz-focusring
. Alternatively, you could just get rid of it, maybe replace it with:focus-visible
and wait for Firefox to catch up. I’m fine with either option.