Extending placeholder selector with nested selector with &-suffix doesn't work
See original GitHub issueWhen using this placeholder selector (compare with mixin - https://gist.github.com/pepa-linha/43ffbce8e60d96e04c7bbe3d22923169)
%component {
background: red;
&-sub {
background: orange;
}
}
.Component {
@extend %component;
}
I get this output
.Component {
background: red;
}
but I would expect this output
.Component {
background: red;
}
/* This selector is missing */
.Component-sub {
background: orange;
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
Sass mixin with nested ampersand prefix - css - Stack Overflow
The solution requires both the use of mixins and placeholder selectors and is a little messy. If we set up our placeholder selector...
Read more >@extend | Stylus
Extending placeholder selectors Stylus has a feature similar to the one in Sass — placeholder selectors. Note that if the selector is...
Read more >Parent Selector - Sass
When a parent selector is used in an inner selector, it's replaced with the corresponding outer selector. This happens instead of the normal...
Read more >When I Use (and Don't Use) Sass Extend • James Steinbach
Don't mix nesting and extends. Only extend placeholders. Try to use an actual selector instead. Using Using Sass's @extend ...
Read more >Selectors Level 4 - W3C
Publication as a Working Draft does not imply endorsement by W3C and ... of and extends the set of selectors defined for CSS...
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 FreeTop 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
Top GitHub Comments
@thany First and foremost, you need to understand that the code that handles placeholders is the exact same code that handles all selectors because placeholders are a type of selector. Secondly, we have to consider use cases that are not built around component definitions using well defined naming systems like BEM, because the use of
&
and@extend
are generic. So the feature request isn’t about placeholders, it’s actually about all selectors so what we have to ask is whether we expect the following to work as indicated:One of the reasons for this decision is that we expect
@extend
to have the exact same behavior across a nesting refactoring. That is, if you had originally written the code:and then later you refactored it to:
You should expect the exact same output. This “feature request” would violate this invariant and hence it would actually introduce a bug from another user’s perspective and use case.
Finally, It seems like some people have a mental model that
@extend
applies before resolving the parent selector, that it is like a search and replace. This is fundamentally a wrong way of thinking about@extend
which creates a document level styling relationship between complex css selectors and can only be applied to full selectors and not to just parts of them.@pepa-linha the stylus behavior isn’t necessarily worse, it’s just a different concept (using the same syntax 🤔) – as long as the concepts are understood, people will know what to expect and behave accordingly. Their model is a simpler one, it’s easier to implement and arguably it’s easier to understand and know what output it will generate – but it lacks the document level guarantees that Sass makes 🤷♂️