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

Limitations on host context selection #1164

Closed
jolleekin opened this issue Apr 3, 2017 · 3 comments
Closed

Limitations on host context selection #1164

jolleekin opened this issue Apr 3, 2017 · 3 comments
Labels
css-scoping-1 Current Work

Comments

@jolleekin
Copy link

Let's say I have a custom element named x-toggle that can be either on or off. I want to style it based on its state and a color mode (light or dark). The color mode is specified by adding a CSS class (.ui-light or .ui-dark) to a parent element (usually html). Is there any way I can achieve the following style rules? Currently, this is impossible.

.ui-light x-toggle.on { ... }
.ui-light x-toggle.on:hover { ... }
.ui-light x-toggle.on:active,
.ui-light x-toggle.on:hover:active { ... }
.ui-light x-toggle.off { ... }
...
@fantasai fantasai added the css-scoping-1 Current Work label Apr 7, 2017
@jolleekin
Copy link
Author

What about introducing :parent-context(<compound-selector>)? Unlike :host-context(<compound-selector>), which matches the host if a parent element matches <compound-selector>, :parent-context only matches a parent element.

:parent-context(.ui-light) :host(.on) { ... }

@jolleekin
Copy link
Author

Any solution?

@tabatkins
Copy link
Member

I don't understand why, in your example, you wouldn't want to turn on the "light" UI when the class is on the host element itself.

Anyway, you can already achieve this:

:host-context(.ui-light):host(:not(.ui-light)) ... {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-scoping-1 Current Work
Projects
None yet
Development

No branches or pull requests

3 participants