Skip to content

Add reference target to shadow root#1353

Open
dandclark wants to merge 14 commits into
whatwg:mainfrom
dandclark:dandclark/reference-target
Open

Add reference target to shadow root#1353
dandclark wants to merge 14 commits into
whatwg:mainfrom
dandclark:dandclark/reference-target

Conversation

@dandclark

@dandclark dandclark commented Feb 4, 2025

Copy link
Copy Markdown
Contributor

Reference Target is a feature to enable using IDREF attributes such as for and aria-labelledby to refer to elements inside a component's shadow DOM, while maintaining encapsulation of the internal details of the shadow DOM. The main goal of this feature is to enable ARIA to work across shadow root boundaries.

In this change, add the referenceTarget property to ShadowRoot and add a definition of reference target that's exported for use in other specs.

See the reference target explainer.


Preview | Diff

Comment thread dom.bs
Comment thread dom.bs Outdated
Comment thread dom.bs
dandclark and others added 4 commits May 6, 2025 23:12
- Add the concept of a "source" for an Event.
- Modify shadow root's "get the parent" algorithm such that events
propagate into the event's source's tree where appropriate.
Comment thread dom.bs
@dandclark

Copy link
Copy Markdown
Contributor Author

@annevk , @smaug---- , this is ready for another review along with whatwg/html#10995. For context on the event propagation change, see WICG/webcomponents#1098. Thanks!

@smaug----

Copy link
Copy Markdown
Contributor

What is the current testing situation? alice added several tests, but this is a rather complicated feature (at least from implementation point of view) so we need to ensure testing coverage is particularly good.
Gecko doesn't fail currently in too many (when run in Mozilla CI).
Chrome fails only some on wpt.fyi.

But are we testing all the complicated cases?

@dandclark

dandclark commented May 19, 2026

Copy link
Copy Markdown
Contributor Author

I've tried to ensure that the WPTs for this are thorough; I and other contributors added quite a few during work on the Chromium prototype.

E.g. https://wpt.fyi/results/shadow-dom/reference-target/tentative/property-reflection.html and https://wpt.fyi/results/shadow-dom/reference-target/tentative/property-reflection-idl-setters.html test reflection behavior for all the properties affected by reference target, with references pointing to and from every HTML element type.

https://github.com/web-platform-tests/wpt/blob/master/shadow-dom/reference-target/tentative/event-path.html covers all the interesting event propagation scenarios discussed in WICG/webcomponents#1098, plus some others I thought of.

All of the platform features testable in WPTs that can be affected by reference target (form submission, commandfor, interestfor, <label> (implicit association and with for)), popovertarget, and aria-labelledby, have WPTs under https://wpt.fyi/results/shadow-dom/reference-target/tentative.

There are a few other ARIA properties affected by reference target that aren't yet testable in WPTs; there are tests for those in the Chromium source tree at https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/shadow-dom/reference-target/tentative/.

For some reason it doesn't seem like the Mozilla CI results are including the full set of tests. There are a larger number of tests in https://wpt.fyi/results/shadow-dom/reference-target/tentative that Gecko is shown as failing that don't appear in the linked Mozilla CI results.

@smaug----

smaug---- commented May 19, 2026

Copy link
Copy Markdown
Contributor

The pref in Gecko isn't enabled in Nightly, so wpt.fyi still shows many tests as failing. The pref is enabled in Mozilla CI.

Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs
Comment thread dom.bs Outdated
Comment thread dom.bs
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated
Comment thread dom.bs Outdated

@smaug---- smaug---- left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable, with the nits annevk has mentioned

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants