Default semantic properties for Custom Elements

Unofficial Proposal Draft,

This version:
https://wicg.github.io/aom
Issue Tracking:
GitHub
Editors:
(Google)
(Apple)
(Google)
(Mozilla)

Abstract

This specification describes the additions to existing specifications which will make it possible for web authors to programmatically express semantics for Web Components.

Status of this document

This specification was published by the Web Platform Incubator Community Group. It is not a W3C Standard nor is it on the W3C Standards Track. Please note that under the W3C Community Contributor License Agreement (CLA) there is a limited opt-out and other conditions apply. Learn more about W3C Community and Business Groups.

1. Defining custom element semantics

1.1. Introduction

This section is non-normative.

Authors may potentially provide semantics for custom elements in two ways:

1.1.1. Defining custom element semantics as part of the custom element definition

Authors may provide immutable default semantics for a custom element by setting properties via the ElementDefinitionOptions object passed in to the CustomElementRegistry.define() method.

The properties set on the ElementDefinitionOptions object become the default values to be used when mapping the custom element to an accessible object.

Note: this is analogous to creating an "immutable class variable" - these semantic properties are associated with the custom element definition, not with each custom element instance. The semantics they define apply to all instances of the custom element.

1.1.2. Defining per-instance custom element semantics

Note: see Web Components issue #758 for up to date information on ElementInternals.

A custom element author may use the ElementInternals object, created via createInternals(), to modify the semantic state of an instance of a custom element in response to user interaction.

The properties set on the ElementInternals object are used when mapping the element to an accessible object.

Note: this is analogous to setting an "instance variable" - a copy of these semantic properties is created for each instance of the custom element. The semantics defined in each apply only to their associated custom element instance object.

1.2. Changes to custom element definition

This section represents changes which should be made to HTML Standard §custom-elements-core-concepts, HTML Standard §custom-element-definition, HTML Standard §custom-elements-api, HTML Standard §element-definition, HTML Standard §upgrades and HTML Standard §custom-element-reactions.

[...]

A custom element may have semantics defined when the custom element is defined. Otherwise, an autonomous custom element does not have any special meaning: it represents its children. A customized built-in element inherits the semantics of the element that it extends.

[...]

A custom element definition [includes]:

A set of default values for semantic properties (optional)
A map, whose keys are each an attribute in either the AccessibilityRole or AriaAttributes interface mixin. The corresponding values are DOMString.

[...]

// Existing IDL
/*
[Exposed=Window]
interface CustomElementRegistry {
  [CEReactions] void define(DOMString name, CustomElementConstructor constructor, optional ElementDefinitionOptions options);
  // ...
};

dictionary ElementDefinitionOptions {
  DOMString extends;
};
*/
ElementDefinitionOptions includes AccessibilityRole;
ElementDefinitionOptions includes AriaAttributes;

dictionary ElementInternals {};

ElementInternals includes AccessibilityRole;
ElementInternals includes AriaAttributes;

Element definition is a process of adding a custom element definition to the CustomElementRegistry. This is accomplished by the define() method. When invoked, the define(name, constructor, options) method must run these steps:

[...]

  1. Run the following substeps:
    1. Let semantics be an empty map.
    2. For each key defined in AccessibilityRole and AriaAttributes:
      1. If the key exists in options, add an entry to semantics with that key and the value provided in options.
    3. If semantics is empty, set it to null.
  2. Let definition be a new custom element definition with name name, local name local name, constructor constructor, observed attributes observedAttributes, lifecycle callbacks lifecycleCallbacks, and, if semantics is non-null, semantic properties semantics.
  3. Add definition to this CustomElementRegistry.

[...]

2. ARIA semantic precedence between ElementDefinitionOptions, ElementInternals and ARIA properties

2.1. Introduction

This section is non-normative

In general, the precedence of semantic properties is that any ARIA property set directly on the Element (either via setting an attribute or via the associated reflected property) overrides a value for the same property on the Element's ElementInternals object, and any ARIA property set either on the Element or the ElementInternals object will override a value set via the CustomElementRegistry.define() method.

2.2. Mapping semantics to the accessibility tree

This section represents changes which should be made to [[html-aam-1.0#mapping-html-to-accessibility-apis]].

2.2.1. Rules for exposing semantics of custom elements

If an element is custom, for each key in the element’s ElementInternals object, the associated value must be mapped to accessibility APIs as if they were a property set on the element.

If the element’s custom element definition includes semantics, the value of each property in semantics must be mapped to accessibility APIs as if they were set on the element, unless there is a conflicting value for the same property in the element’s ElementInternals object, or in a property set on the element.

Conformance

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[DOM]
Anne van Kesteren. DOM Standard. Living Standard. URL: https://dom.spec.whatwg.org/
[HTML]
Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://tools.ietf.org/html/rfc2119
[WebIDL]
Cameron McCormack; Boris Zbarsky; Tobie Langel. Web IDL. 15 December 2016. ED. URL: https://heycam.github.io/webidl/

Informative References

[INFRA]
Anne van Kesteren; Domenic Denicola. Infra Standard. Living Standard. URL: https://infra.spec.whatwg.org/

IDL Index

// Existing IDL
/*
[Exposed=Window]
interface CustomElementRegistry {
  [CEReactions] void define(DOMString name, CustomElementConstructor constructor, optional ElementDefinitionOptions options);
  // ...
};

dictionary ElementDefinitionOptions {
  DOMString extends;
};
*/
ElementDefinitionOptions includes AccessibilityRole;
ElementDefinitionOptions includes AriaAttributes;

dictionary ElementInternals {};

ElementInternals includes AccessibilityRole;
ElementInternals includes AriaAttributes;