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: CSS Element selectors local scope (encapsulation) #120

Open
nabilnaffar opened this issue Dec 21, 2017 · 2 comments
Open

Comments

@nabilnaffar
Copy link

Feature request: Support CSS elements selectors local scope

We're developing components library and we're looking for a way to locally scope CSS element selectors styles.
for example:

:local(button){
   color: tomato;
} 

I want this style to affect only 1 component and not the whole buttons on the page of whoever uses it.

(the :local selector doesn't affect the button style encapsulation. )

Is there already a library/plugin that does that?

If not - a possible solution would be to add hashed custom attribute as Angular does:
https://blog.thoughtram.io/angular/2015/06/29/shadow-dom-strategies-in-angular2.html - ViewEncapsulation.Emulated

TL;TR:

<button custom-generated-attribute >Press here</button>
button [custom-generated-attribute]{
   color: tomato;
}
@TrySound
Copy link
Member

And how do you consider apply these styles to your component? Like this?

const template = `
  <button ${styles.button}>Press here</button>
`;

@nabilnaffar
Copy link
Author

No need to specifically apply the style (as with classes) since it's element selector.
Problem with those kind of styles is that they are global and I'm looking for a way to encapsulate them.
Shadow Dom has this feature but it's not supported yet in all browsers.
Second thing I found is the way Angular does that as I specified.

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