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.

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.

capture d ecran 2018-10-16 a 20 35 40

Steps to Reproduce

Link: https://codesandbox.io/s/52l1po8nlx

  1. Click any of the Select drop-downs
  2. 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
brianchirlscommented, Oct 28, 2018
1reaction
brianchirlscommented, Oct 17, 2018

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 as theme.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.

Read more comments on GitHub >

github_iconTop 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 >

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