You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been working with integrating ReactSelect with our own theming library and I've come across a few issues.
Conflicts in theme namespacing - If you use Emotion components to override ReactSelect components you can get conflicts in the theme object that we override. For example, in my global ThemeProvider I have a colors key with a different format that means that I end up having a weird hybrid of the colors object passed down and this causes issues. It would be better for react select to pass down theme={{ 'react-select': theme }} instead of theme={theme} as this allows prevents collisions.
The named colors are too generic; primaryprimary75primary50 and primary25 - I can't control what colors are used in what situations so it would make more sense to use named values like menuBorderactiveBackgroundactiveText etc so we know what we are theming and what it affects.
I know this is a pretty opinionated and technically I can work around this by replacing all Components with custom ones but this feels like it defeats the purpose of a "theme" option.
To me, it makes more sense to name the theme colors as for what they are actually used for rather than having to figure out that primary25 is used only for when an element is "focused".
Another issue is that due to us using neutral0 for both the selected text color and the control background I can't theme these individually, not to mention there is no text color available for when a value is focussed so using darker colors there won't work - for example when implementing a Dark Theme.
Reacted by Samuil Goranov, Joan Mira, Mike Viens, lucas nascimento, Jody Steele, Misha Slizenko, Joep Kemperman, Aneela Chagarlamudi, Max Donchenko, Arnaud Barré and 30 more
Ran into this problem today. Took over an hour to tease out what generic named colour was used for what aspect of the select box (in retrospect I should have just looked at the source, it's relatively easy to see the usages there). Using semantic names would definitely be way better.
Reacted by Davis Ford, Jovica Aleksic, Tonya Abna, Chris Lane, John Datserakis, Mikołaj Rozwadowski, Sandeep Joel, Rajesh Sitaraman, Ritesh Shrivastav, Arve Seljebu and 35 more
Reacted by Tyler Caceres, Scott Gibson, Mark Howells-Mead, Sachin Raja, Conor, scottrepreneur, Laura, Maheshraj R P, Mattéo Peronnet and Emily
Reacted by Sandeep Joel, Tyler Caceres, Frida Erdal, Abhijeet Singh, Miłosz Wiśniewski, Scott Gibson, Markku Rontu, Mark Howells-Mead, Sachin Raja, Conor and 8 more
Reacted by John Datserakis, Sandeep Joel, Tyler Caceres, Sachin Raja, Conor, Jay Kaku, scottrepreneur and Emily
@JedWatson is there any way for users to use their own, existing Emotion theme object?
I figured when we resorted to custom sub-components like a custom <Option />, we'd be able to use our theme object.
Edit: We ended up wrapping the parent of our react-select component with withTheme() and then overriding the built in theme by passing that to the custom components. Pretty clunky, but workable. It would be a lot better if React-Select didn't override the user theme by default.
@hovoodd thank you so much for posting that, it was so helpful! I'm quite meh at frontend, so I had to jam a lot of colors (ie. pink, purple) while debugging to see what would happen. I don't think I would have been able to work if you hadn't posted that!!!
My use case : I needed to make react-select work with light/dark mode in Material UI's theme system, so I'm posting my code I used to make that work for someone who has to do something similar.
In my case, I detect the user preference using a media query. However, you might be using a class set higher up the hierarchy; in that case, you could do:
Activity
steelej commentedon Aug 13, 2019
Ran into this problem today. Took over an hour to tease out what generic named colour was used for what aspect of the select box (in retrospect I should have just looked at the source, it's relatively easy to see the usages there). Using semantic names would definitely be way better.
jqueryisamonad commentedon Aug 21, 2019
Working with the theme is just terrible.
Maybe it'll be helpful to somebody.
Nantris commentedon Mar 21, 2020
@JedWatson is there any way for users to use their own, existing Emotion theme object?
I figured when we resorted to custom sub-components like a custom
<Option />, we'd be able to use ourthemeobject.Edit: We ended up wrapping the parent of our
react-selectcomponent withwithTheme()and then overriding the built in theme by passing that to the custom components. Pretty clunky, but workable. It would be a lot better if React-Select didn't override the user theme by default.jeffshek commentedon Aug 9, 2020
@hovoodd thank you so much for posting that, it was so helpful! I'm quite meh at frontend, so I had to jam a lot of colors (ie. pink, purple) while debugging to see what would happen. I don't think I would have been able to work if you hadn't posted that!!!
My use case : I needed to make react-select work with light/dark mode in Material UI's theme system, so I'm posting my code I used to make that work for someone who has to do something similar.
(A demo of working react-selects should be on the forms w/light and dark themes on https://app.betterself.io/demo later tonight)
joeyfigaro commentedon Jun 15, 2022
Did anything ever come of this @JedWatson? Trying to deal with overriding the theme to support a dark mode.
gsusI commentedon Sep 2, 2022
Super helpful resource here: https://stackoverflow.com/a/60993034/3198983
Especially when you don't know on your back-end which theme will be loaded, for example when using Tailwindcss
gsusI commentedon Sep 4, 2022
My final approach has been to inject styles for dark mode using jsx:
idand aclassNamePrefix:In my case, I detect the user preference using a media query. However, you might be using a class set higher up the hierarchy; in that case, you could do: