-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reference Target: How should we treat invalid reference targets for relations set via Element IDL attributes? #1089
Comments
I see the WPT tests assert that IDL attributes do follow https://github.com/web-platform-tests/wpt/blob/master/shadow-dom/reference-target/tentative/anchor.html#L105 |
Another question related to this and to #1071: what should happen in this case? <input id="input">
<fancy-listbox id="listbox">
<template
shadowrootmode="open"
shadowrootreferencetarget="BAD_ID"
>
<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>
Should it log the |
I think APIs should generally return the custom element (that handles the forwarding into its shadow tree). It seems weird if the APIs didn't work just because you used a custom element (with forwarding). For the later question I think we have to answer another question. When do we consider a custom element a viable ID target?
It seems potentially somewhat performance-sensitive to do 3, but not sure. |
This might also duplicate #1071? |
I'm not quite sure I follow your answers, sorry @annevk. The question I was trying to ask in the issue description, which I didn't explain very well in hindsight, was whether relationships set via Element IDL attributes (as opposed to content attributes which necessarily use ID strings) should also follow reference target forwarding when computing the relationships. The explainer doesn't address this; it only says:
and
The explainer is clear on how the IDL attribute getters should work when the referenceTarget is valid: they should return the element in the appropriate scope (i.e. the element which was set via the setter, which must be a descendant of a shadow-including ancestor of the element hosting the attribute). While the explainer doesn't address how the IDL attribute setters should work, the WPTs indicate that the intent was for attribute set via IDL attributes to work similarly to attribute set via content attributes.
When you say the APIs should return the custom element, are you answering the later question in #1089 (comment), regarding whether the IDL attribute getters should return null/empty list for an invalid referenceTarget?
The reason I think that this is a slightly different question to #1071 is that #1071 (part 2) uses a getter-only API as an example. #1071 seems to conclude that an invalid referenceTarget is analogous to a bad ID, so even if the ID reference to the host is valid, the attribute is invalid. Because the attribute is invalid, the IDL getter returns null, just as it would if the content attribute was a bad ID. With an IDL attribute setter, there is no ID involved, so 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, per my reasoning below. 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.
I think a custom element can be a viable ID target when either:
Depending on the implementation, this could be performance sensitive when resolving an ID target (note that this is different from either Regardless of the decision we make for DOM APIs, we will still need to implement that validity logic for whatever the consequences are of the relation. For example, a |
I'm still a little uncertain on what the invalid ID behavior should look like, but assuming valid IDs I think attribute setters should cause |
@dandclark Yeah, I agree. I've updated the issue to focus more on the invalid referenceTarget question, and to make note of the consensus on the earlier question. |
#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:
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?
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:
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.
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">
?The text was updated successfully, but these errors were encountered: