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

Missing ability to break parent selector chain for ampersand #2401

Closed
aczekajski opened this issue Nov 14, 2017 · 4 comments
Closed

Missing ability to break parent selector chain for ampersand #2401

aczekajski opened this issue Nov 14, 2017 · 4 comments

Comments

@aczekajski
Copy link

I am using some external scss file. Let's assume I want to isolate the external styles to work only for elements that are wrapped in some additional element. In effect, I end up with

.my-wrapper {
  @import "external";
}

In general this works ok, until trailing ampersand selector happens to be used in external styles. We then end up with a structure like this:

.my-wrapper {
  .external-children {
    .external-parent & {
      color: red;
    }
  }
}

which in turn gets compiled to this:

.external-parent .my-wrapper .external-children {
  color: red;
}

while in fact I wanted to achieve this:

.my-wrapper .external-parent .external-children {
  color: red;
}

Of course current behavior is correct, but it seems that currently there is no way to achieve what I wanted without editing external.scss. I tried experimenting with @at-root but it removes .my-wrapper completely from the selector chain. A directive similar to @at-root might be needed to do that. So I can type something like this:

.my-wrapper {
  @reset-parent {
    .external-children {
      .external-parent & {
        color: red;
      }
    }
  }
}

which will cause & to not see the part of parent selector that happened before @reset-parent but still be output as style inside the wrapper.

@nex3
Copy link
Contributor

nex3 commented Nov 16, 2017

I understand what you want to do here, but it's a pretty narrow use-case. I don't think it's worth adding an entirely new directive for.

@M3kH
Copy link

M3kH commented Feb 12, 2019

I will argue that this is not a narrow use-case since css-module is spreading.

@aczekajski
Copy link
Author

@M3kH you meant that you will argue that this IS a narrow use-case, right? 😅

@M3kH
Copy link

M3kH commented Feb 12, 2019

@aczekajski correct :-)

In short worth looking again to this, since stuff like:

:local(.embed){

    @at-root {
        @import "@my-component-library/my-component";
        ...
    }
...
}

Should help to isolate style in a more modular way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants