Skip to content

ARIA attribute reflection uses DOMString? but they are not enumerated attributes #10037

Closed
@domenic

Description

@domenic

What is the issue with the HTML Standard?

ARIAMixin on Element says:

The ARIAMixin getter steps given element, idlAttribute, and contentAttribute are to return the result of the getter algorithm for idlAttribute reflecting contentAttribute on element.

The ARIAMixin setter steps given element, idlAttribute, contentAttribute, and value are to perform the setter algorithm for idlAttribute reflecting contentAttribute on element, given value.

So, let's go look at what the getter algorithm for, say, ariaLive reflecting aria-live="" would be. ariaLive is defined as

[CEReactions] attribute DOMString? ariaLive;

i.e. it's a DOMString?. But HTML's DOMString? getter reflection says:

Assert: attributeDefinition indicates it is an enumerated attribute.

Assert: the reflected IDL attribute is limited to only known values.

Assert: contentAttributeValue corresponds to a state of attributeDefinition.

These asserts generally fail.

The spec might imply that the first succeeds: the definition for aria-live="" states that its "Value:" is "token", and the ARIA type mapping states that "token" "Value:" should somehow map to HTML's Keywords and enumerated attributes section. (With what invalid value default and missing value default? What keyword vs. state mapping, exactly?)

For the second assert (and thus the third as well), there's no evidence that the attributes are limited to only known values. Testing in browsers, it's certainly not the case: document.body.ariaLive = "foo" will happily work, with document.body.ariaLive === "foo" on the next line succeeding.

And of course, picking ariaLive was already stacking the deck in our favor. If we did ariaDescription, which corresponds to the "string"-"Value:"d `aria-description="" attribute, then certainly it would not be an enumerated attribute.

Note that this seems to be implemented in all browsers, according to WPTs.


I see a few paths forward here:

  • 1A. Allow DOMString? reflection for all attributes. Try to avoid using it in the future for such unrestricted cases.

  • 1B Allow DOMString? reflection for attributes starting with aria-* only, as a legacy exception.

  • 2A Decide that DOMString? is a nicer way of doing string reflection than DOMString (since it distinguishes between the attribute being missing and it being present as the empty string), and going forward use it for all new HTML attributes that reflect as strings.

  • 2B Decide that DOMString? is a nicer way of doing string reflection than DOMString, and try to not only use it going forward, but to also change the behavior of existing HTML attributes.

  • 3 Try to change away from DOMString? to instead just DOMString. The behavior change here is that absent attributes would return the empty string, and setting the value to null would no longer remove the attribute but would instead set the attribute's value to the string "null".

  • 4 On a case-by-case basis, update the ARIA IDL attributes to have the best possible reflection semantics, including possibly "limited to only known values" enumerated attribute behavior.

There are some previous issues tracking this on the ARIA side, most notably w3c/aria#1110, but I wanted to summarize the current state of things. Especially since the easiest path, like 1A or 1B, would involve changes solely to HTML.

/cc @annevk @cookiecrook @alice

Metadata

Metadata

Assignees

No one assigned

    Labels

    a11y-trackerGroup bringing to attention of a11y, or tracked by the a11y Group but not needing response.topic: reflectFor issues with reflected IDL attributes and friends

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions