Skip to content

.elementInternals accessor property #11040

@WilcoFiers

Description

@WilcoFiers

What problem are you trying to solve?

ElementInternals provides several powerful options for setting accessibility related properties. These include role, various ARIA states, and labels. It is critical for accessibility test tools to be able to learn about this information. Many such tools, including axe-core (and thus Lighthouse, Accessibility Insights, etc.), IBM Equal Access, ANDI, and HTML Code Snipper are built to run directly in the page, and so only have access to native DOM features.

For these tools to work out accessibility information about custom elements they need to know 1. if an custom element has ElementInternals attached, and 2. what is on that ElementInternals object.

What solutions exist today?

There is no solution today. We've considered different options but none of them really work.

  1. window.getComputedAccessibility(). This was proposed as an alternative method for accessing accessibility information. This proposal looks unlikely to happen as it creates potential performance problems in browsers. Even if this eventually gets implemented, a direct accessor allows accessibility tools more direct access.

  2. Override Element.attachElementInternals: This can only work if the tool can be loaded on the page before scripts are executed. This cannot be done reliably. Many such tools defer loading until they are needed to prevent unnecessary adding load time when they are not needed.

  3. Look to see if one of the element's properties has an instance of ElementInternals stored on it. Unfortunately looping over an element's custom properties to find what's on it triggers getters, which can have unforseen side effects. This also only works if the ElementInternals is stored as a public property, which is by no means guaranteed.

  4. Call .attachElementInternals() to see if one is attached. That only tells us if ElementInternals is not attached, not what's on it. It also could prevent a delayed attachment from happening, creating unforeseen problems in the page.

How would you solve it?

Add a new .elementInternals property to HTMLElement. If there is an ElementInternals attached, this property returns the ElementInternals object. If not, the property returns null.

This would be consistent with how the .shadowRoot property works for attached shadow DOM trees. Looking at GitHub search, .elementInternals is used by some tools so if we want to avoid conflicts with existing perhaps .attachedElementInternals, I get no results for that.

Anything else?

In axe-core the lack of support has been raised multiple times. Currently the open issue has more thumbs up than any other open issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accessibilityAffects accessibilityaddition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interesttopic: custom elementsRelates to custom elements (as defined in DOM and HTML)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions