Re: [WICG/webcomponents] Reference Target: How should we treat invalid reference targets for relations set via Element IDL attributes? (Issue #1089)

Given the tentative conclusion that #1071 seems to be converging towards (treating the reference as totally invalid rather than referring to the shadow host), I agree @alice that your option (2) is a better fit:

> 2. 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.

If I’m understanding correctly, that means we’d get behavior like this:

```html
<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>
<script>
input.ariaControlsElements = [ listbox ];
console.log(input.ariaControlsElements);  // logs `null`
document.querySelector("#fancy-listbox").shadowRoot.referenceTarget = "real-listbox";
console.log(input.ariaControlsElements);  // logs `listbox` since the reference target is valid now!
</script>
```

Which seems reasonable given the validity checks that already exist in element-reflecting IDL attributes.


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

Message ID: <WICG/webcomponents/issues/1089/2594204895@github.com>

Received on Thursday, 16 January 2025 00:28:02 UTC