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

classList is only applied if className is given #9

Open
dsimon-dev opened this issue Dec 17, 2021 · 3 comments
Open

classList is only applied if className is given #9

dsimon-dev opened this issue Dec 17, 2021 · 3 comments

Comments

@dsimon-dev
Copy link

dsimon-dev commented Dec 17, 2021

Considering the following styled div:

const Div = styled("div")`
  color: red;
`

The component:

<Div classList={{ foo: true }} />

results in <div class="go1681785550"></div>, but it should also contain foo.

Adding a className prop:

<Div className="bar" classList={{ foo: true }} />

results in <div class="bar go1681785550 foo"></div>, containing both foo and bar.

@ryansolid
Copy link
Member

Thanks for reporting. I suspect this has to do with the fact that class/className overwrites all classes and classList applies them piecewise. Depending on how they are applied they trample each other. I am looking at ways to improve this if possible, but it is innately difficult given the way reactivity independently updates. We's almost need to change how all class applications apply with the existence of a classList property. My general advice for right now is not mixing these and we will have to see if there is a reasonable fix.

@dsimon-dev
Copy link
Author

Thanks for the quick response, my workaround for now is just using the className prop with classnames.

@httnn
Copy link

httnn commented Jun 2, 2022

just ran into this, would be awesome if you could use classList with styled components! it's oftentimes much more convenient than to pass in and handle a custom prop in the component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants