-
Notifications
You must be signed in to change notification settings - Fork 65
Allow ::slotted(selectors) #113
base: master
Are you sure you want to change the base?
Conversation
Hi James, Looking at It looks like Shadow DOM is also introducing a new selector, As far as the PR goes, I will need tests for it. I don't have time to do that in depth tonight, but I'll try to get to it soon. Ian |
(And by "do that", I meant "review the code".) |
74146a2
to
f952d9d
Compare
Heya. As I continued to work with shadow DOM, I also needed If you have any existing css infrastructure testing, I would be happy to put together an automated test. I see GssParserTest is probably good enough for this? I think there is also support for |
Note, the current working draft says that So, unless/until that changes, the most you'd want to do is issue a warning to developers that attempting to use this in a stylesheet will not work. Also note, the draft shows ::slotted as containing complex selectors, but the discussion it is based on in the web component spec authors' github repo, the consensus was to support simple selectors only, as I made the PR match the recommendations I was able to grok from the still evolving spec: "Note: ::slotted() can only represent the elements assigned to the slot. Slots can also be assigned text nodes, which can’t be selected by ::slotted(). The only way to style assigned text nodes is by styling the slot and relying on inheritance." If we want to be pedantic, the only usable prefixes of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this! I think it looks good, generally, but I have a few comments.
If only simple selectors are allowed, then reusing the code we have for :not(
selector
)
, as you have done, seems right to me. :host(
selectors > here
)
and :host-context(...)
obviously need a special case, too. It would be great, though, if we could make the tokens "generic" and have just one for functions that take simple selectors and another for functions that take compound selectors.
I don't know if I want to try to enforce things like enforcing the usable prefixes of ::slotted
in the grammar. Instead, I think that should be in a compiler pass were we to want it. If we do that, we can also warn about /deep/
, which is currently supported.
You don't have to make that change in this PR unless you'd like to.
Also, if >>>
isn't supported in rules, then I think I wouldn't even bother mentioning it.
Also, you can add tests here:
Thanks!
Ian
@@ -707,6 +707,8 @@ PARSER_END(GssParserCC) | |||
// Special handling needed because ':not' takes simple selectors as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just generalize this to two tokens: SIMPLE_SELECTOR_FUNCTION
and SELECTOR_FUNCTION
? It seems like a bunch of duplicate code in the pseudo
expansion would go away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye. I agree that the duplication here is less than stellar.
However, I think the semantics of :not
is slightly different.
:not()
takes only a simple selector; one tag name, class name or id. I tested this in browser console, and it did not like any compound selectors ( :not(elementName.className)
did not work)
The other three, ::slotted
, :host
and :host-context
all support a compound selector (what simpleSelector() actually matches). ::slotted(div.clazz)
is valid here.
I think simpleSelector
should be renamed to compoundSelector
, and then a new simpleSelector
:
elementName()
| id()
| className()
| pseudo()
I will test tonight that :host-context
does not also support combinators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not
supports compounding only through duplication:
div:not(.class1):not(.class2)
} | ||
{ | ||
t = <COLON> { beginLocation = this.getLocation(); tokens.add(t); } | ||
( ( t = <IDENTIFIER> { pseudo = t.image; tokens.add(t); } ) | ||
| | ||
( // ::slotted( simple_selector ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the docs above under pseudo
.
closure-stylesheets.iml
Outdated
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I really want this to be checked in. What's the advantage?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No advantage. It's an intellij project file.
Will remove this file, and perhaps add a .gitignore for it.
943a638
to
4ef475c
Compare
Unlike ::slotted(), which only allows simple selectors inside the parens, :host and :host-context allow complex selectors to be placed inside the parens.
4ef475c
to
d5fbf75
Compare
Hi @iflan Sorry I kind of forgot about this pull request. I updated the comment per your request in the BNF. I don't think we decided on any naming for splitting up the pseudo definition. I'd be happy to break it up if you decide what you want and let me know. Thanks! |
I'll add some tests shortly. |
It would be great if you also add support for ::cue() pseudo selector: |
Custom Elements we're the perfect solution for me, until i couldn't style the children.. I do not get how custom elements are of any use without that. |
::slotted selectors are necessary for ShadowDOM V1
It may make sense to allow
::anyname(selectors)
instead of cherry-picking individual named selectors, but I do not know the code well enough to make such a judgement."If" tests are desired, let me know where to add them, and I can add that to PR.