Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Add support for Shadow DOM CSS #5

Merged
merged 5 commits into from
Jul 5, 2021

Conversation

marchbox
Copy link
Contributor

@marchbox marchbox commented Jul 2, 2019

When working on a Custom Element, if Shadow DOM is turn on, selectors like [dir="rtl"] .foo in Custom Element’s CSS won’t work, unless you add dir attribute to an element inside the Shadow DOM.

While the workaround could work, it’s not really a good idea to add dir attribute when it’s not necessary, e.g. if the value of :root[dir] has changed, you have to make sure the dir also gets updated in your Shadow DOM.

So I’m proposing to add an option to transform :dir() selector for Shadow DOM, i.e. instead of creating a leading [dir] selector, create leading :host-context([dir]) selector, in this way, Shadow DOM will be aware of the directional context of where the component is living in.

This is not very perfect as this will also transform global CSS, i.e. CSS rules that are not in any components. But I don’t have a good idea of how the plugin can figure out whether or not the current rule is part of Shadow DOM or not. So perhaps developers can preprocess global CSS separately from Shadow DOM CSS.

@marchbox
Copy link
Contributor Author

Friendly ping.

@kawazoe
Copy link

kawazoe commented Feb 7, 2021

Unfortunately, :host-context() is "on track" to be dropped from the spec so I don't think this PR will ever get merged: w3c/csswg-drafts#1914

@jonathantneal jonathantneal merged commit 465a0ad into csstools:master Jul 5, 2021
romainmenke pushed a commit to csstools/postcss-plugins that referenced this pull request Nov 16, 2021
* Add support for shadow DOM CSS

* Change spaces to tabs for consistency

* Fix comment language

* Make sure this won't do anything to selectors with leading :root

Co-authored-by: Zacky Ma <[email protected]>
Co-authored-by: Jonathan Neal <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants