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

[docs] className order or specificity #7763

Closed
gfpacheco opened this issue Aug 15, 2017 · 4 comments
Closed

[docs] className order or specificity #7763

gfpacheco opened this issue Aug 15, 2017 · 4 comments
Labels
docs Improvements or additions to the documentation

Comments

@gfpacheco
Copy link
Contributor

If I have a component A with some styles using CSS-in-JS, that can receive a className prop like this:

function A({ classes, className }) {
  return <div className={classNames(classes.root, className)} />;
}

And another component B that uses component A:

function B({ classes }) {
  return (
    <div className={classes.root}>
      <A className={classes.a} />
    </div>
  );
}

The thing is: the B classes are being added to the dom before A classes, and since they're all a single class selector the last one have higher priority.

Is there a right way of handle this?

@oliviertassinari
Copy link
Member

I'm not sure to follow, how is this related to Material-UI? A reproduction example would be much better. You can use codesandbox or webpackbin :). The only specificity logic we have in Material-UI is right here: withStyles.js.

@oliviertassinari oliviertassinari added v1 waiting for 👍 Waiting for upvotes labels Aug 15, 2017
@gfpacheco
Copy link
Contributor Author

I was trying to build a component for Material-UI, I don't know how to reproduce it in a simple example, but let's try with this.

Is there any way of making the A component stylesheet definition have higher priority over the one received by props?

@oliviertassinari oliviertassinari added docs Improvements or additions to the documentation and removed waiting for 👍 Waiting for upvotes labels Aug 15, 2017
@oliviertassinari oliviertassinari changed the title className order or specificity [docs] className order or specificity Aug 15, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 15, 2017

Yes, you can with the index property. We should document it.

-export default withStyles(styles)(A);
+export default withStyles(styles, {
+  index: 0,
+})(A);

@oliviertassinari
Copy link
Member

I have improved the documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

No branches or pull requests

2 participants