Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2] Option to disable CSS-in-JSS entirely #2706

Closed
majelbstoat opened this issue Jun 13, 2018 · 26 comments
Closed

[V2] Option to disable CSS-in-JSS entirely #2706

majelbstoat opened this issue Jun 13, 2018 · 26 comments
Assignees
Labels
issue/reviewed Issue has recently been reviewed (mid-2020)

Comments

@majelbstoat
Copy link

I have a NextJS app that is server side rendered, which uses the built in styled jsx. I'd really rather not have to add emotion-server to the application, just so there's no flash of unstyled select boxes. I would also much prefer to keep my style definitions to one system and one format.

I absolutely adore the functionality of react-select, but enforcing a specific CSS-in-JS solution for a component that will have to live within so many different kinds of environments seems like a misstep. IMO, the things it offers, like theming, should be done at an application- or framework-level, not a single component level.

Using className alone somewhat gets me there, but I now have two sets of CSS classes and two styling systems competing for primacy on the page, which is hard to debug, diagnose, and manage.

I realise that it's probably not going away, and assuming that is a non-starter, can we have the ability to just disable emotion, and do all the styling ourselves? That will be painful, but at least there will only be one authority.

@gwyneplaine
Copy link
Collaborator

@JedWatson this is a valid line of inquiry, and may be in lined with roadmap for an unthemed select export. Would be nice to get your thoughts on this.

@jossmac jossmac added the v2 label Jul 5, 2018
@ghost
Copy link

ghost commented Jul 17, 2018

This is a very valid point and a reason for me not currently upgrading to the latest version, I use this library in several projects and all implementations have custom styles, some of which already use CSS-in-JS libraries. I'm interested to find out the rational behind this decision?

@jharris4
Copy link
Contributor

I'd also like to have a way to break the dependency on the emotion package for v2. I found this issue after reading the v2 upgrade guide's section of styling (https://react-select.com/styles), more specifically this paragraph:

While we encourage you to use the new Styles API, it's good to know that you still have the option of adding class names to the components to style via CSS.

It would be great to have an example/docs of how to style v2 using something like the react-select.css from v1.

If the ability to disable css-in-jss is added then it would be great to also show how to do that in the same example/docs section.

@wszgxa
Copy link

wszgxa commented Aug 13, 2018

While we encourage you to use the new Styles API, it's good to know that you still have the option of adding class names to the components to style via CSS.

It's hard to add CSS by class name. Because emotion will add css in <style>....</style>. If you add CSS by <link rel="stylesheet" href="xx/main.css">, you must add many !important in your CSS file to rewrite the base css.

@edmorley
Copy link

This is a blocker for us using react-select unfortunately.

The use of emotion means:

If there was a (tree-shakeable) way to disable emotion when using react-select, it would avoid both issues.

@WitoTV
Copy link

WitoTV commented Nov 20, 2018

This is as well blocking me from using react-select. I have all styles compiled to one style.css file so I would love to have an option to get rid of inline styles and see some normal classes not css-1hwfws3.

Using existing classes makes it really hard to even try to write my own styling that makes any sense...

Please give us option to disable CSS-in-JSS.

@eckdanny-osi
Copy link

The docs indicate react-select is friendly with css-modules. I too am looking to avoid translating a bunch of [s]css to css-in-js. Ideally I'd like to opt out of css-in-js entirely, style components with our existing sass constructs, and pass className mappings via props or context.

Does a working example of using css-modules exist?

@bbay
Copy link

bbay commented Jan 8, 2019

is this open to consideration?
It would be really nice to have the option to either embrace css-in-js or disable it.

For projects that are not yet into the css-in-js craze it makes sense to just disable it and use the good 'ol stylesheets.

@simondiep
Copy link

I'm working on updating a legacy app from v1 to v2 and came across this issue. My component now looks really weird. Any chance backwards-compatibility could be added?

@sedenardi
Copy link

This issue and the bundle size issue mentioned in #2972 have led our team to hold off indefinitely from upgrading to V2. Unfortunately I don't have any experience with emotion, so don't feel comfortable submitting a PR to address the issue (nor do I know if it would be accepted, given the lack of comment from contributors to this issue).

We love this package and are very grateful for all the hard work the contributors have put into it.

@ArranJacques
Copy link

This makes working with react-select incredibly frustrating as it forces an opinionated way of styling the components on you. It would be incredibly useful to have an option to disable css-in-js completely and instead just pass standard class names to the components. This then gives us the freedom to choose how we style the components.

@lukewhitmore
Copy link

I wholeheartedly agree .. we need to be able to disable CSS-in-JS.

The fact that this route has been chosen, and is impossible to override has stopped us from using react-select.

@hcharley
Copy link
Contributor

Emotion seems to be racking up performance hits in my tests. Would be nice if there was a way to simply turn it off.

Perhaps there could be a webpack plugin that excludes emotion and we maintain a community CSS file?

@jharris4
Copy link
Contributor

In case it helps anyone, I literally just forked react-select at version 1.30 into a new package called react-select-css, and also upgraded the components to no longer use deprecated lifecycles (warnings in React 16.9).

I haven't gotten around to making a README etc, but it's published to npm and working great for me: https://www.npmjs.com/package/react-select-css

@StarpTech
Copy link

StarpTech commented Apr 16, 2020

Great issue and I experience the same. I don't want to use a component that adds unnecessary complexity / size to my application.

By the way, that is the big strength of Cascading StyleSheet that you aren't coupled to the specific component 😄

Providing only a default theme in a SASS file and working with className and classNamePrefix would be great.

This approach would be compatible with CSS and CSS-in-js solutions without adding any overhead.

Example in CSS/SASS

<style>
.react-select {
   padding: 4px;
 }
  .react-select .sub-component {
  }
</style>

<Select></Select>

Example in styled-components with nesting

const Thing = styled.div`
  .react-select {
    padding: 4px;
  }
  .react-select .sub-component {
  }
`
<Thing>
	<Select></Select>
</Thing>

Example in emotion with nesting

const select = css`
  .react-select {
    padding: 4px;
  }
  .react-select .sub-component {
  }
`
<Select css={select}></Select>

@onionhammer
Copy link

onionhammer commented Jul 1, 2020

This library doesn't work too well with CSS modules OOTB as far as I can tell.

In React if I import styles via

import styles from './some.module.css'

there is no effective way to utilize the styles to style the react-select.

@gregmartyn
Copy link

gregmartyn commented Jul 15, 2020

@onionhammer we're able to get it to work with what feels like a hack:
jsx:

<Select
	className={style.location}
	classNamePrefix={style.location}

and in css

.location {
	{rules for the select itself here}
	& .location__control {
		{rules for the select's control here}
	}
}

more info https://react-select.com/styles#using-classnames

@bladey bladey added issue/reviewed Issue has recently been reviewed (mid-2020) and removed issue/reviewed Issue has recently been reviewed (mid-2020) labels Aug 24, 2020
@ebonow
Copy link
Collaborator

ebonow commented Jan 14, 2021

Greetings,

A solution has been posted here to disable the default styles: #2872 (comment) While the generated classNames will still be present in the DOM, the corresponding styles will not be added to the page.

const styleProxy = new Proxy({}, {
    get: (target, propKey) => () => {}
});

<Select styles={styleProxy} {...} />

Here is a working demo to illustrate it: codesandbox

This should satisfy this condition such that this issue can be closed. If anyone has any other questions or concerns, feel free to reply and this can be re-opened if necessary.

@ebonow ebonow closed this as completed Jan 14, 2021
@timakhalaya
Copy link

Greetings,

A solution has been posted here to disable the default styles: #2872 (comment) While the generated classNames will still be present in the DOM, the corresponding styles will not be added to the page.

const styleProxy = new Proxy({}, {
    get: (target, propKey) => () => {}
});

<Select styles={styleProxy} {...} />

Here is a working demo to illustrate it: codesandbox

This should satisfy this condition such that this issue can be closed. If anyone has any other questions or concerns, feel free to reply and this can be re-opened if necessary.

This approach in no good at all

@Methuselah96
Copy link
Collaborator

Methuselah96 commented Nov 1, 2021

We're planning on create an "unstyled" version of react-select where you can bring your own styles (or turn them off completely).

@timakhalaya
Copy link

We're planning on create an "unstyled" version of react-select where you can bring your own styles (or turn them off completely).

That would solve a ton of issues then 🚀

@loicnestler
Copy link

loicnestler commented Nov 4, 2021

@Methuselah96 is there any ETA for this?

Edit:
I just found out about this trick (Link to CodePen by @ebonow):

const styleProxy = new Proxy(
  {},
  {
    get: (target, propKey) => () => {}
  }
);

const App = (props) => {
  return <Select styles={styleProxy} options={basicOptions} />;
};

And then proceed to style the select box using classNames.

Should work for now, in case anyone also needs react-select unstyled.

@Methuselah96
Copy link
Collaborator

No, there's no ETA at the moment. The top two priorities are fixing menu positioning and creating an unstyled version but it's hard to estimate how soon we can finish those up since the amount of time we can work is not always consistent.

@zedtux
Copy link

zedtux commented Mar 2, 2022

@Methuselah96 any progress on that "unstyled" version please ?

@Uni2K
Copy link

Uni2K commented Oct 25, 2023

How is it going with the unstyled version? It would be great to have a prop to disable "emotion css" completely.

@addlistener
Copy link

addlistener commented Aug 11, 2024

I guess this is still relavant?

Especially if you need your own instance of emotion there's conflict

emotion-js/emotion#2383
#4780
#4541

And this package is outdated.
https://www.npmjs.com/package/react-select-no-emotion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/reviewed Issue has recently been reviewed (mid-2020)
Projects
None yet
Development

No branches or pull requests