Re: [WICG/webcomponents] Selection APIs for Shadow DOM (#79)

So I'm in the process of updating the explainer with the points mentioned in my prior comment. And I ran across a set of issues that I don't see an immediate (good) solution for. Both can be seen using the [last part of example #2](https://github.com/mfreed7/shadow-dom-selection#2-editor-component-inside-shadow-dom) from the explainer. In that example, an editor Web Component (`<x-editor>`) that does **not** use shadow DOM is nested inside another Web Component (`<parent-component>`) that **does** use shadow DOM.

## Problem <span>#</span>1
Since the editor component itself, which needs selection info, does not contain a shadow root, what should it pass in to the shadowRoots argument here: `selection.getComposedRange({shadowRoots: [what?]})`? I suppose it could walk up the shadow-including tree from `this`, and pass in the first shadow root it finds? That feels a bit odd, for a component that really doesn't want to use Shadow DOM, but finds itself located inside one.

## Problem <span>#</span>2
This brings up another issue in the definition of exactly **which** shadow roots are required in the call to `getComposedRange({shadowRoots: []})`. When we discussed this, and in the explainer, only the "deepest" shadow root was needed, which was enough to reveal knowledge of that shadow root and all ancestor shadow roots. But that will necessarily reveal selections in the entire shadow-including tree above the component, which might be deeply nested. If the purpose of the `shadowRoots` parameter to `getComposedRange()` is to limit selections to "known" shadow roots, then it doesn't really work in this case. A fix to this would be to require **all** shadow roots to be included, but then that's ambiguous. What gets returned if you only provide "your" shadow root, but the selection surrounds "you" but begins and ends in a shadow root above you?

-----

Both of these point (me at least) back to the original proposal which doesn't require passing in `open` shadow roots. It feels like all of the same problems will exist in that case, but we won't require developers to also do extra work to walk the tree looking for shadow roots to provide. Do the proponents of requiring `open` shadow roots to be specified have a suggestion for a fix for these problems?

-- 
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/79#issuecomment-961536259

Received on Friday, 5 November 2021 00:30:36 UTC