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

Allow &-nesting of element name #11

Closed
awdyson opened this issue Aug 17, 2021 · 7 comments
Closed

Allow &-nesting of element name #11

awdyson opened this issue Aug 17, 2021 · 7 comments

Comments

@awdyson
Copy link

awdyson commented Aug 17, 2021

It seems as though nesting with & just concatenates whatever follows the ampersand.
So { root: { '&a': { backgroundColor: ... } } } becomes:
image
It'd be nice to be able to & element names as well.

@awdyson
Copy link
Author

awdyson commented Aug 17, 2021

Also, I'm realizing that an empty class is created.
Is that something that's cleaned up in production mode? Or maybe a shortcoming of emotion?
If not, seems like something to optimize.

@garronej
Copy link
Owner

Thank you for reporting,
I will investigate although this is more likely to be related to emotion.
When you type this: { root: { '&a': { backgroundColor: ... } } } you want that the backgroundColor only apply if the element the class is apply to is an <a> am I correct? Like:

<div className={classes.roo} /> //Dosen't applies
<a className={classes.root} /> //Applies

@garronej
Copy link
Owner

garronej commented Aug 18, 2021

I released a new version.
Is this by any chance related to your problem?

@awdyson
Copy link
Author

awdyson commented Aug 19, 2021

It isn't, but it's nice to know that I can use dynamic names like that.

My issue stems from a quirk of MUI + ReactRouter.
This is part of the process of using the <List> components in a custom <SubNav>:

<ListItemButton
  component={forwardRef<HTMLAnchorElement>((itemProps, ref) => (
    <NavLink
      activeClassName={classes.active} // this appears before ListItemButton's style

That said, I was able to get around this using '&[href]' to add specificity.
I just figured it was worth noting that &-element references weren't being handled as I'd expect, to the point where I questioned whether &-non-pseudo worked.

@garronej
Copy link
Owner

Ok, thanks for the detailed explanation.
I'll close for now as I have no way to fix it myself. :/
Maybe it would be worth opening an issue on the emotion repo...

PS: As you mentioned ReactRouter maybe you'd like to checkout type-route, I love this lib!

@awdyson
Copy link
Author

awdyson commented Aug 19, 2021

<a {...routes.fooBar().link}>Foo Bar</a>
Ooo, that is a nice solution.
I'm enjoying the surge of headless UI kits.

@garronej
Copy link
Owner

Hi @awdyson,
I am sorry I had to update the API for nested selector. The approach based on css was broken.
https://github.com/garronej/tss-react#selecting-children-by-class-name

gitbook-com bot pushed a commit that referenced this issue Jan 22, 2022
gitbook-com bot pushed a commit that referenced this issue Jul 10, 2022
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

2 participants