- From: Takayoshi Kochi <notifications@github.com>
- Date: Tue, 30 May 2017 20:13:50 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/463@github.com>
(See [crbug.com/710797](https://crbug.com/710797) for the background) The problem is, that `shadowRoot.querySelector('::slotted(div)')` (or `querySelectorAll`) will not return anything even when the context object (the `shadowRoot`) contains `<slot>` and a `<div>` is slotted to it. Demo: http://jsbin.com/jafetekipi/edit?html,js,output (currently both Blink and WebKit fail) MDN document of [Document.querySelector()](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) says: > CSS Pseudo-elements will never return any elements, as specified in the [Selectors API](https://www.w3.org/TR/selectors-api/#grammar) Note that this "Selectors API" links to Selectors API level 1 (an old spec). The latest draft as of today ([Selectors Level4](https://drafts.csswg.org/selectors-4/)) doesn't say about how `querySelector()` should work for pseudo-elements, and neither does DOM spec. In the past, `::before` or `::first-line` etc. never matched any real element in DOM tree, but `::slotted(div)` can match a real element in DOM tree, even though it is in a different tree. Here I see the following problems in the current specs: 1. DOM spec isn't clear about whether `querySelector` can match some pseudo elements (`::slotted()`). 2. DOM spec isn't clear about whether `querySelector` can return an element outside the node tree of the context object. 3. `::slotted()` is a pseudo element, but can point to a real element. For 3, this is not a matter of DOM spec. The rationale for `::slotted()` being a pseudo element is that it points to an element in another tree, and we wanted to restrict the selector in parentheses to a simple/compound selector (not allowing complex selector). If it were a combinator, any selector would be allowed to the right side. Note that issue 2 is also relevant to https://github.com/w3c/webcomponents/issues/78 (Support `>>>` combinator in static profile). -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/463
Received on Wednesday, 31 May 2017 03:14:28 UTC