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.

I had these lines at the top of my file:

import Select from 'react-select';
import 'react-select/dist/react-select.css';

but the select was showing up un-styled. I made a subtle change in my webpack config file by changing this line:

{test: /\.css$/, loader: 'style!css?modules!postcss'}

to this:

{test: /\.css$/, loader: 'style!css!postcss'}

and now it works.

Does that mean I cannot use css modules with React-Select?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:21

github_iconTop GitHub Comments

36reactions
bensussmancommented, Dec 7, 2018

Does this all still apply with react-select v2 and above?

Specifically what is painfully missing from the react-select docs is an example that uses custom styles with CSS Modules. The docs claim that CSS Modules are supported: https://react-select.com/styles#using-classnames but that does not seem to be the case, because a prefix is simply not good enough for CSS Modules: the class names are compiled into something different for use at run time. I am able to get around this by using the :global keyword in my stylesheet, but this is circumventing CSS Modules, not using them! Is this the approved way to set custom styles?

Please update the docs to provide an example using CSS Modules and react-select. Thanks.

11reactions
Neddzcommented, Jul 3, 2017

Hello guys,

I solved this problem by importing the react-select css like this in my js: import '!style-loader!css-loader!react-select/dist/react-select.css';

You need to add the -loader part if you are using webpack@2.4.1 or above.

I found this solution here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation about css-modules - GitHub
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. All URLs (...
Read more >
What are CSS Modules and why do we need them?
According to the repo, CSS modules are: CSS files in which all class names and animation names are scoped locally by default. So...
Read more >
Component-Scoped Styles with CSS Modules - Gatsby
A CSS Module is a CSS file in which all class names and animation names are scoped locally by default. CSS Modules let...
Read more >
Adding a CSS Modules Stylesheet - Create React App
CSS Modules let you use the same CSS class name in different files without worrying about naming clashes. Learn more about CSS Modules...
Read more >
A deep dive into CSS Module - LogRocket Blog
According to the official CSS Module GitHub repository, a CSS Module is a CSS file in which all class names and animation names...
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