[WICG/webcomponents] Reference Target: How to handle invalid ID references? (Issue #1071)

This question was brought up by @Westbrook in https://github.com/WICG/webcomponents/pull/1067#pullrequestreview-2234222929:
> Is there a related section that points out what happens to references when `referenceTarget` doesn't resolve an element? Maybe the practicalities of "just like when there is no element of that ID" are assumed. However, the idea that there _is_ an element, but it's "nothing", in certain cases, could be surprising.

It's not yet spelled out in the [Reference Target Explainer](https://github.com/WICG/webcomponents/blob/gh-pages/proposals/reference-target-explainer.md). An example of this situation is when the shadow root's reference target is invalid; in this case `INVALID_ID`. What is the `<input>`'s `aria-activedescendant` in this case?
```html
<input
  role="combobox"
  aria-activedescendant="fancy-listbox"
/>
<fancy-listbox id="fancy-listbox">
  <template
    shadowrootmode="closed"
    shadowrootreferencetarget="INVALID_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>
```

There are two options when a shadow root's `referenceTarget` refers to an invalid ID (no element with the given ID exists in the shadow tree):
1. The reference is invalid. Act as if the attribute refers to an element that doesn't exist.
   - In the example above, that would mean the `aria-activedescendant="fancy-listbox"` attribute is invalid, and there is no active descendant.
   -  This seems to better follow the component author's intent. The missing element might be added later, and it could be unexpected for references to target the host in the meantime. 
2. The reference applies to the host. Act as if there is no `referenceTarget` set. 
   - In the example above, the `fancy-listbox` itself would be the active descendant.
   - This avoids confusion about why a seemingly valid ID reference isn't working to resolve to an element.

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

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

Received on Thursday, 22 August 2024 19:55:09 UTC