Nested elements inside modifiers are a known issue . There are many workarounds.
Variable way
Save the block element in a variable.
And use it to interpolate when creating an element inside a modifier.
.block { $block: &; &__element { property: value; } &--modifier { property: value; #{$block}__element { property: value; } } }
See conclusion below.
Functional way
1. Create a function that returns a block element.
It will get the parent selector and cut the word to -- (which is a block). Looks like hacks, but this is the easiest way to go.
@function block() { $selector: str-slice(inspect(&), 2, -2); $index: str-index($selector, '--') - 1; @return str-slice($selector, 0, $index); }
2. Use the interpolation function.
Which will return the name of the block, so you do not need to repeat it.
.block { property: value; &--modifier { property: value; #{block()}__element { property: value; } } }
See conclusion below.
Both methods will be displayed on:
.block { property: value; } .block--modifier { property: value; } .block--modifier .block__element { property: value; }
Diéssica
source share