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.

Components with secondary classnames

See original GitHub issue

Hi, I’m wondering if there is a solution to using styled-components with existing libraries. Lots of libraries adopt customization to css via multiple className props. For example, react-select uses className and optionClassName in a component. Would it be useful to support something like:

const MySelect = styled(ReactSelect)`
  border: red;
  [optionClassName]
  color: blue;
`

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:21 (9 by maintainers)

github_iconTop GitHub Comments

6reactions
kittencommented, Apr 22, 2017

Just pass in className to the generated styled component and it’ll be appended on the prop 😉

5reactions
mxstbrcommented, Jul 3, 2017

We’ve decided against introducing a method that let’s you manually get a CSS class name from a CSS string to avoid people overusing it and thusly defeating the whole point of the library. (it’s strictness)

I’m going to close this issue because this is now possible with v2 and the .attrs selector:

const optionClassName = 'option';

const MySelect = styled(ReactSelect).attrs({
  optionClassName,
})`
  .${optionClassName} {
    // style an option here!
  }
`
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add multiple classes to a ReactJS Component?
You can create an element with multiple class names like this: <li className="class1 class2 ...
Read more >
Adding Multiple Class Names in React Components
We can use the classnames package to make adding multiple classes easier. It works for both static and dynamic classes. To use it,...
Read more >
Passing className to components in React
In React, we are familiar with the concepts of a className on components. It's the way React adds the class attribute to an...
Read more >
Passing className to components in React - Daily Dev Tips
In React, we are familiar with the concepts of a className on components. It's the way React adds the class attribute to an...
Read more >
Advanced Usage - styled-components
styled-components generates an actual stylesheet with classes, and attaches those classes to the DOM nodes of styled components via the className prop. It ......
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