Re: [WICG/webcomponents] Reference Target: what type should the `referenceTarget` attribute be? (Issue #1093)

alice left a comment (WICG/webcomponents#1093)

@annevk The explainer did include [some comments](https://github.com/WICG/webcomponents/blob/gh-pages/proposals/reference-target-explainer.md#add-referencetargetelement-attribute-that-targets-an-element-object) on this, e.g.:

> - \[A `referenceTargetElement` attribute\] does not unlock any net-new functionality. Since `referenceTarget` only works with elements inside the shadow root, every element that could be a target is accessible by a string ID reference.
> > Note: This is in contrast to the ARIAMixin attributes like ariaLabelledByElements, which do unlock the new functionality of referring out of the shadow DOM. In that case, the complexity is necessary to include in the ARIAMixin design.
> 
> - At a basic level, Reference Target is augmenting the existing functionality of referring to elements by ID string. It seems in line with the design to require using ID strings.

I'm not sure I agree with all of the arguments listed in the explainer, but I do think the design goals and constraints are slightly different here than for something like `popovertarget` or `aria-labelledby`:

- Since a shadow root is not an Element, there is no option to use `setAttribute()` to use an ID string if that's what the author prefers (for example, if the intent is for the shadow root to be serializable)
- There is some extra complexity compared with a regular Element, because there are three interacting interfaces:
   - the `template` element
   - the `ShadowRootInit` dictionary
   - the `ShadowRoot` object.

I think it makes sense to at least offer the option of having a `referenceTarget` attribute which takes a DOMString, and matches the `referenceTarget` property in `ShadowRootInit`. As the explainer points out, offering a `referenceTargetElement` attribute as well offers no additional functionality in this context other than convenience, so I think it can at least be deferred.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/WICG/webcomponents/issues/1093#issuecomment-2664237530
You are receiving this because you are subscribed to this thread.

Message ID: <WICG/webcomponents/issues/1093/2664237530@github.com>

Received on Monday, 17 February 2025 23:44:03 UTC