Skip to content

Add reference target#10995

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

Add reference target#10995
dandclark wants to merge 37 commits into
whatwg:mainfrom
dandclark:dandclark/reference-target

Conversation

@dandclark

@dandclark dandclark commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

Reference Target allows authors to specify an element inside a shadow root to be the target of any ID references referring to the host element. This would enable 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.

See the reference target explainer.

At a high level, the spec change consists of these parts:

  • Define the concept of "resolving the reference target" on an element, following an IDREF from a host element to its target in the shadow, and potentially recursing.
  • Update the get-the-attr-associated-element algorithm (and its array-of-elements form) to follow reference target.
  • Centralize the definitions of ID reference attributes and list-of-ID-reference attributes as "element reference" and "set of element reference" attributes instead of repeating these definitions throughout the spec.
  • Update uses of ID throughout the spec, where applicable, to use the new reference-target-aware get-the-attr-associated-element.
  • Avoid exposing reference target elements in shadows from element-returning IDL properties by retargeting the result before returning.

See also the corresponding whatwg/dom#1353 which adds the definition of reference target used in this PR.
 

(See WHATWG Working Mode: Changes for more details.)


/common-dom-interfaces.html ( diff )
/common-microsyntaxes.html ( diff )
/document-lifecycle.html ( diff )
/dom.html ( diff )
/form-control-infrastructure.html ( diff )
/form-elements.html ( diff )
/forms.html ( diff )
/iframe-embed-object.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/input.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/links.html ( diff )
/microdata.html ( diff )
/nav-history-apis.html ( diff )
/parsing.html ( diff )
/popover.html ( diff )
/scripting.html ( diff )
/tables.html ( diff )

@dandclark

Copy link
Copy Markdown
Contributor Author

@annevk, @domenic, this isn't quite ready to land yet as there are still a few open questions to sort out (at least WICG/webcomponents#1087 and WICG/webcomponents#1093), plus missing implementor positions. But I don't expect most of the mechanics in this PR to change, so I think it would be great to get feedback on whether the approach we've used here is agreeable.

See also whatwg/dom#1353

Thanks!

@alice

alice commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

There's also a WIP PR against ARIA to account for these changes: w3c/aria#2474

There are some open questions being discussed there on exactly how to refer to the HTML concepts, since ARIA needs to be language-independent, but it will certainly refer to these spec concepts in some form.

@lukewarlow lukewarlow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be updated to make use of the new [Reflect] syntax.

Comment thread source Outdated
Comment thread source
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
@dandclark
dandclark requested a review from lukewarlow August 6, 2025 21:37
@dandclark

Copy link
Copy Markdown
Contributor Author

This should be updated to make use of the new [Reflect] syntax.

Thanks @lukewarlow! Fixed now (it wouldn't let me merge the suggestions directly due to merge conflicts).

@lukewarlow
lukewarlow requested review from lukewarlow and removed request for lukewarlow August 6, 2025 21:41
@lukewarlow

Copy link
Copy Markdown
Member

I'm not sure how GitHub actually lets you dismiss change suggestions but consider this me dropping my change suggestions as they've been resolved :)

@keithamus keithamus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've done an initial review pass, got about half way, but I thought I'd provide my review commentary so far because I think if I continue I may end up repeating themes.

Some meta commentary:

  • I think another formatting pass needs to be done.
  • I am a little worried about the retargeting steps, I wonder if this can be simplified to avoid retargeting and to resolve a reference target where necessary.

Comment thread source
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source
<span>tree</span>.</p>
a valid <span>single element reference</span> attribute
<span data-x="single-element-reference-refers-to">referring to</span> a <code>form</code>
element.</p>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This isn't perhaps super clear. I think this means that the final element from single element reference should be a form element

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.

That's right. I'm not really sure of a clearer way to put it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this all works well for the Developer Edition of the standard as now we're phrasing conformance requirements in terms of algorithms aimed at implementers?

Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source Outdated
Comment thread source

@alice alice 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.

I had to apply all the code suggestions manually, because I foolishly pushed my changes before I'd applied them.

Comment thread source Outdated
dandclark and others added 22 commits June 26, 2026 10:44
…d attr target element(s) and unresolved attr target element(s)
This concept is used to propagate events into the source's tree under
certain circumstances.
…ire a focus event to pass relatedTarget to be set as concept rather than attribute
…mmand are fired, set composed and relatedTarget.
@annevk
annevk force-pushed the dandclark/reference-target branch from caec5d7 to 6e4196f Compare June 26, 2026 08:50
@annevk

annevk commented Jun 26, 2026

Copy link
Copy Markdown
Member

Do you remember the case(s) when composed was fiddled with in the past?

I think we changed it for UI events. And more recently we weren't sure with these toggle events.


I fixed quite a few issues with this PR. Further review welcome. The outstanding issue is the synthetic events. It seems we should align them with precedent and have the constructors initialize the relatedTarget concept correctly.

@dandclark

Copy link
Copy Markdown
Contributor Author

Thanks for taking the time @annevk. I'm going to be out on vacation next week but will make the change for synthetic events when I get back.

@annevk annevk added the addition/proposal New features or enhancements label Jul 3, 2026
@smaug----

Copy link
Copy Markdown

One thing I haven't checked in tests: aria-labelledby and non-trivial DOM mutations in multiple levels of nested Shadow DOMs. (Support for aria-labelledby is one thing missing currently in Gecko's referenceTarget implementation)

@dandclark

Copy link
Copy Markdown
Contributor Author

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

Labels

addition/proposal New features or enhancements

Development

Successfully merging this pull request may close these issues.

6 participants