Skip to content
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

Shadow DOM and ElementInternals ARIAMixin properties #8544

Open
alice opened this issue Nov 24, 2022 · 5 comments · May be fixed by #8932
Open

Shadow DOM and ElementInternals ARIAMixin properties #8544

alice opened this issue Nov 24, 2022 · 5 comments · May be fixed by #8932
Labels
topic: custom elements Relates to custom elements (as defined in DOM and HTML) topic: reflect For issues with reflected IDL attributes and friends. topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@alice
Copy link
Contributor

alice commented Nov 24, 2022

This came out of the discussion on #8442.

Do Element/FrozenArray<Element> attributes on ElementInternals need to be subject to the same Shadow DOM validation rules as the same IDL attributes on Elements?

For example:

<my-listbox>
  # shadowRoot
  | <my-listitem>Generated option 1</my-listitem>
  | <my-listitem>Generated option 2</my-listitem>
  | <my-listitem>Generated option 3</my-listitem>
</my-autocomplete>
class MyListbox extends HTMLElement {
  constructor() {
    super();
    this._internals = this.attachInternals();
    this._internals.role = "listbox";
    // etc
  }

  // ...

  // called when a user selects a list item via mouse or keyboard
  listItemSelected(selectedListItem) {
    // not allowed:
    // this.ariaActiveDescendantElement = selectedListItem;

    // allowed?
    this._internals.ariaActiveDescendantElement = selectedListItem;
  }
}

@annevk and I were chatting about this and it seems that the constraints which led to disallowing elements in Shadow DOM from being used for Element type reflecting IDL attributes on Elements may not apply when it comes to ElementInternals, since ElementInternals won't generally be available to any in-page scripts, and thus can't lead to undesirable dependencies on implementation details within Shadow DOM.

@nolanlawson we were chatting about this in AOM, so I thought you might also have some thoughts to add here.

@mrego
Copy link
Member

mrego commented Nov 24, 2022

CC @rniwa as he might have thoughts about this too.

@annevk annevk added topic: shadow Relates to shadow trees (as defined in DOM) topic: custom elements Relates to custom elements (as defined in DOM and HTML) labels Nov 24, 2022
@annevk
Copy link
Member

annevk commented Nov 24, 2022

I do think we still want the same overall approach as at the very least we do not want to return elements that are not connected to the same document. (I.e., you can assign whatever, but you might not be able to get it back out.)

But I think there's some merit to this idea. ElementInternals is private after all so any private references will remain as private as ElementInternals is.

At the very least not hiding references to elements inside the shadow tree associated with the element ElementInternals is from, but I don't immediately see a principled reason why it couldn't be any shadow tree in the same document.

cc @whatwg/components

@nolanlawson
Copy link

nolanlawson commented Nov 29, 2022

At the very least not hiding references to elements inside the shadow tree associated with the element ElementInternals is from, but I don't immediately see a principled reason why it couldn't be any shadow tree in the same document.

Original comment

This makes sense to me. There is maybe (?) even a principled reason to expose elements inside the shadow root associated with the host element, since it's possible to leak the shadow root using attachInternals:

console.log(element.shadowRoot) // null
const internals = element.attachInternals()
console.log(internals.shadowRoot) // #shadow-root (closed)

(Of course the component can defensively prevent this by calling attachInternals() in its constructor, but if the author forgets, it may leak.)

(Just occurred to me it's orthogonal whether an element can leak its shadowRoot, so hiding the comment.)

If you have access to an ElementInternals, you also have access to the associated shadowRoot of the associated host element, so it makes sense to me that the ElementInternals can reference elements inside of the shadow root. As for referencing any shadow root in the document, that's a bonus for sure. 🙂

@annevk annevk added the agenda+ To be discussed at a triage meeting label Feb 20, 2023
@annevk
Copy link
Member

annevk commented Feb 20, 2023

I cannot attend triage until Feb 23 it seems. If folks could give this a look before then I'd appreciate it, but otherwise I can explain then.

annevk added a commit that referenced this issue Feb 22, 2023
Other changes:

* Remove reflection of unrestricted double as it is buggy and unused.
* The DOMString getter steps did not account for a missing attribute.
* The native accessibility semantics map was renamed to the internal content attribute map as it's now a more general reflection concept.

Corresponding ARIA PR: w3c/aria#1876.

Fixes #8442.

Follow-up:

* w3c/core-aam#152
* w3c/aria#1110
* #3238
* #8544
* #8545
* #8926
* #8927
* #8928
* #8930
annevk added a commit that referenced this issue Feb 22, 2023
In particular allow them to point to any known element, as long as that has the same shadow-including root as the ElementInternals's element. This is not considered to break encapsulation as ElementInternals itself is encapsulated.

Tests: anyone want to volunteer?

Fixes #8544.
@annevk annevk linked a pull request Feb 22, 2023 that will close this issue
4 tasks
@annevk
Copy link
Member

annevk commented Feb 22, 2023

I've done part of this work in #8932 but as noted there we might want to address some bigger issues in this space first. Help welcome with regards to review and tests and such.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: custom elements Relates to custom elements (as defined in DOM and HTML) topic: reflect For issues with reflected IDL attributes and friends. topic: shadow Relates to shadow trees (as defined in DOM)
Development

Successfully merging a pull request may close this issue.

5 participants