From c18ef3c959b6cf6a275870a503383097e3930add Mon Sep 17 00:00:00 2001
From: Domenic Denicola User agent requirements for implementing Accessibility API semantics on HTML
- elements are defined in HTML Accessibility API Mappings.
@@ -12833,8 +12836,38 @@ interface DOMStringMap {
AccessibilityMixin
interface, with its associated
+ get the accessibility IDL attribute and
+ set the accessibility IDL attribute hooksRequirements related to ARIA and to platform accessibility APIs
Let map be element's native accessibility semantics + map.
If map["role
"] exists,
+ then return it.
Otherwise, return no role.
Similarly, for a custom element element, the default WAI-ARIA state and + property semantics, for a state or property named stateOrProperty, are determined as + follows:
+ +Let map be element's native accessibility semantics + map.
If map[stateOrProperty] exists, + then return it.
Otherwise, return the default value for stateOrProperty.
For an example of this in action, see the + custom elements section.
+ +Conformance checker requirements for checking use of ARIA role
and aria-*
attributes on
@@ -66449,6 +66482,61 @@ customElements.define('my-checkbox', MyCheckbox);
</form>
+
By using the appropriate properties of ElementInternals
, your custom element can
+ have default accessibility semantics. The following code expands our form-associated checkbox from
+ the previous section to properly set its default role and checkedness, as viewed by accessibility
+ technology:
class MyCheckbox extends HTMLElement {
+ static get formAssociated() { return true; }
+
+ constructor() {
+ super();
+ this._internals = this.attachInternals();
+ this._checked = false;
+ this.addEventListener('click', this._onClick.bind(this));
+
+ this._internals.role = "checkbox";
+ this._internals.ariaChecked = false;
+ }
+
+ get form() { return this._internals.form; }
+ get name() { return this.getAttribute('name'); }
+ get type() { return this.localName; }
+
+ get checked() { return this._checked; }
+ set checked(flag) {
+ this._checked = !!flag;
+ this._internals.setFormValue(this._checked ? 'on' : null);
+ this._internals.ariaChecked = this._checked;
+ }
+
+ _onClick(event) {
+ this.checked = !this._checked;
+ }
+}
+customElements.define('my-checkbox', MyCheckbox);
+
+ Note that, like for built-in elements, these are only defaults, and can be overridden by the
+ page author using the role
and aria-*
attributes:
<!-- This markup is non-conforming -->
+<input type="checkbox" checked role="button" aria-checked="false">
+
+<my-checkbox role="button" aria-checked="false">
+<script>
+ document.querySelector('my-checkbox').checked = true;
+</script>
+
+ Custom element authors are encouraged to state what aspects of their accessibility semantics
+ are strong native semantics, i.e., should not be overriden by users of the custom element. In our
+ example, the author of the my-checkbox
element would state that its role
+ and aria-checked values are strong native semantics, thus discouraging code such as the above.
checkValidity()
Returns true if internals's
target element has no validity problems; false otherwise.
- Fires an invalid
event at the element in the latter case.
-
invalid
event at the element in the latter
+ case.
reportValidity()
labels
Returns a NodeList
of all the label
elements that
- internals's target element is associated with.
-
role
[ = value ]Sets or retrieves the default ARIA role for internals's target element, which will be used unless the page author
+ overrides it using the role
attribute.
aria*
[ = value ]Sets or retrieves various default ARIA states or property values for
+ internals's target element, which will be used
+ unless the page author overrides them using the aria-*
+ attributes.
By using the role
and aria*
properties
+ of ElementInternals
, custom element can set default accessibile roles, states, and
+ property values for their custom element, similar to how native elements behave. See the example above for more details.
Each custom element has a native accessibility semantics map, which is + a map. See the Requirements related to ARIA and to platform + accessibility APIs section for information on how this impacts platform accessibility + APIs.
+ +ElementInternals
includes the AccessibilityMixin
mixin. The IDL
+ attributes provided by this mixin are used to manipulate the target element's native accessibility semantics
+ map, as follows:
To get the accessibility IDL attribute
+ for ElementInternals
, given internals, idlAttribute, and
+ contentAttribute:
Let map be this ElementInternals
's target element's native accessibility semantics
+ map.
If map[contentAttribute] exists, + then return it.
Return null.
To set the accessibility IDL attribute for ElementInternals
, given
+ internals, idlAttribute, contentAttribute, and
+ value:
Let map be this ElementInternals
's target element's native accessibility semantics
+ map.
If value is null, then remove + map[contentAttribute].
Otherwise, set map[contentAttribute] to value.