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

Feature request: extend & class with element name #2536

Closed
thany opened this issue Jul 9, 2018 · 1 comment
Closed

Feature request: extend & class with element name #2536

thany opened this issue Jul 9, 2018 · 1 comment

Comments

@thany
Copy link

thany commented Jul 9, 2018

I'd like to be able to do something like this:

.filters {
    label.& { ... }
    p.& { ... }
}

Which would compile to:

label.filters { ... }
p.filters { ... }

There is probably a huge can of worms in here somewhere, but it boils down to being able to prepend & with an element name. It's not all that weird when you consider that appending something is already possible, but prepending isn't (or so it seems).

One workaround Ive found is pretty convoluted, and I might be overthinking it:

.filters{
    @at-root #{selector-append(label,&)} { ... }
    @at-root #{selector-append(p,&)} { ... }
}

The @at-root in my particular case works, but it won't when .filters from my example is nested yet again in something. If I don't put @at-root it will still prepend .filters even though & is used already.

@nex3
Copy link
Contributor

nex3 commented Jul 10, 2018

Duplicate of #1425

You can work around this a little more simply like so:

.filters{
    @at-root label#{&} { ... }
    @at-root p#{&} { ... }
}

You could also encapsulate this in a mixin:

@mixin append-parent($selector) {
  @at-root #{$selector}#{&} {@content}
}

.filters{
    @include append-parent("label") { ... }
    @include append-parent("p") { ... }
}

@nex3 nex3 closed this as completed Jul 10, 2018
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