- From: Caleb Williams <notifications@github.com>
- Date: Sat, 10 Apr 2021 07:59:22 -0700
- To: WICG/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <WICG/webcomponents/issues/921@github.com>
I've done a little digging, though admittedly not a super deep dive so I aplolgize if this has been brought up elsewhere. Would it make sense to add a `ownerRoot` property to a `ShadowRoot` instance? This language is aligned with `ownerDocument` but it would serve to provide access to the `DocumentOrShadowRoot` to which any given shadow root instance is attached. This could be very helpful for accessibility controls or for controls that need to somehow query their surroundings. A simple use case would be password fields that need to ensure data matches between two components or if an element wants to query from a datalist: ```html <datalist id="list"> <!-- options --> </datalist> <label for="foo">Naive combobox example</label> <x-combobox list="list" id="foo"></x-combobox> <script> class Combobox extends HTMLElement { #internals; constructor() { super(); this.#internals = this.attachInternals(); this.attachShadow({ mode: 'open' }); this.#init(); } #init() { const options = this.shadowRoot.ownerRoot.querySelector(`#${this.getAttribute('list')}`); // parse options } } customElements.define('x-combobox, Combobox); </script> ``` I have a couple more complex use cases for this that right now I'm walking the parent tree until I find a shadow host which is easy enough, but I'm sure there are a number of other use cases out there and this could be a nice quality-of-life improvement. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/WICG/webcomponents/issues/921
Received on Saturday, 10 April 2021 14:59:35 UTC