Confusing behavior with ampersand selector
See original GitHub issueHi,
I’m having confusing behavior with the plugin. I’m not quite sure this is a bug or expected behavior but I couldn’t find any answer for this online neither docs.
Steps to reproduce
Create a styled component
const StyledComponent = styled(Component)`
.parent {
& .hede {
color:black
}
}`
Expected Behavior / Output
.parent .hede{color:black;}
Actual Behavior / Output
.iQAcRJ .parent .hede{color:black;}
It includes the unique class of the component when I use ampersand sign to get parent selector. Is it normal? If yes, is there any way to get parent selector like SASS?
Cheers
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
LESS: Secrets of the Ampersand - SLaks.Blog
One of the less-documented features of the LESS language is the ampersand selector, which refers to the parent selector inside a nested selector ......
Read more >sass - Target immediate parent with ampersand (SCSS)
I'm experiencing what I think is odd behavior in scss. I have a class nested 2 levels deep and I'm trying to target...
Read more >The Sass Ampersand
You can qualify a selector by putting the & on the right. Meaning, select the button class only when a child of a...
Read more >Confusing CSS behaviors that actually make sense - YouTube
CSS can be infuriating at times. There are some really strange things that it does... BUT a lot of those infuriating things happen...
Read more >Documentation
extend({ props: { checkpoints: { type: 'array', default: function () { return []; } } } });. NOTE: Both array and object have...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The id in the example is a placeholder to demonstrate what s-c generates, so this.
Is treated like sass would treat the following.
That is to say, it uses the same parent > child name-spacing* mechanism found in sass.
Not sure i see the problem, the only difference between the expected vs actual is the added specificity.
@mrtkrcm It’d be helpful to understand what you’re actually trying to achieve apart from your current approach 😉 I hope that I can help you nonetheless for now.
I understand that you’re trying to apply some kind of BEM modifiers as sibling identifiers here? This is actually not something we’d recommend, but to detail what
&
does,The parent selector, or ampersand, or simply
&
, resolves to the component class. This is not the dynamic class that is generated depending on dynamic props. Thus&
is going to resolve to the “wider” component’s id.At the same time you’re trying to achieve something that doesn’t behave like the CSS nesting dictates it to behave.
So maybe you can detail your use case and we can help you to clear up the confusion