-
Notifications
You must be signed in to change notification settings - Fork 391
Reference Target: How should we treat invalid reference targets for relations set via Element IDL attributes? #1089
Description
#1071 discusses how invalid reference targets should be handled when computing the browser-internal ("true") target of an ID-based relationship. The consensus in that issue is that an invalid reference target:
- should be treated browser-internally like an invalid ID, i.e. as if the attribute value was itself an invalid ID; and
- should be treated likewise by read-only IDL attribute getters like
label.control; i.e. those getters should return null even though an element with the ID in question technically exists in the same tree.
How should attributes set via IDL attributes work in this situation?
- I think you could make an argument that you should always get back the element that you set, assuming that element is a descendant of a shadow-including ancestor.
- However, I think you could also make an argument that it should only return the element that you set if it is also a valid value - i.e. that it has no referenceTarget set, or has a valid referenceTarget set. This would be analogous to how you can set an IDL attribute to be an element that is not a descendant of a shadow-including ancestor, but it won't be returned from the getter.
My personal slight preference would be for (2), though I could easily be persuaded otherwise. This would make those IDL attribute getters marginally slower, as we would need to check validity before returning the appropriate value. However, it would also give an indication that the relationship has not been set successfully, and work analogously to the read-only IDL attributes.
To address the original question in this issue, there seems to be a consensus based on the discussion on the earlier text of this issue, and also the WPT tests, that:
- relationships set up via IDL attribute setters like:
should work identically to relationships set via content attributes like:
el.ariaLabelledByElements = [ customElementWithReferenceTarget ];
i.e. that the referenceTarget should be followed in both cases; and<input aria-labelledby="id-for-custom-element">
- when the reference target is valid, that the IDL attribute getters should return the element[s] that were set:
i.e. that the getters should not return elements inside shadow roots, even if those elements are the "true" target of the relationship.
const labels = [ customElementWithReferenceTarget ]; el.ariaLabelledByElements = labels; el.ariaLabelledByElements[0] === labels[0];
Original text
The explainer proposes that IDL attribute getters not return the referenceTarget element, and I strongly agree there.
However, this leaves open the question of what should happen with IDL attribute setters.
<input id="input">
<fancy-listbox id="listbox">
<template
shadowrootmode="open"
shadowrootreferencetarget="real-listbox"
>
<div id="real-listbox" role="listbox">
<div id="option-1" role="option">Option 1</div>
<div id="option-2" role="option">Option 2</div>
</div>
</template>
</fancy-listbox>input.ariaControlsElements = [ listbox ];In this case, should the internal aria-controls relationship (i.e. what is exposed to the accessibility tree) be with the <fancy-listbox>, or the <div role="listbox">?