Web components
Each element's attributes, keyboard and accessibility are on the page of the pattern it enhances.
A few small custom elements,
each added only because native HTML cannot do the job. Before reaching for one, check whether an
element already covers it: <dialog>, <details>, the
popover
attribute and invoker commands
handle many cases that used to need script, and most molecules need none.
The rule
Every element here:
- exists because HTML or CSS cannot do something, and its header comment says what;
- enhances native markup that already works without JavaScript (progressive enhancement): content stays readable and links, buttons and sections stay usable with the script off;
- uses the light DOM: no shadow root, so the molecule CSS and your own CSS style the markup directly, and there is no second styling API;
- follows the matching ARIA Authoring Practices Guide pattern, and adds ARIA roles only when it also adds the keyboard behavior those roles promise;
- is one ES module with no dependencies and no build step, named with the
dui-prefix, and documents its API, events and keyboard in its header comment.
Load one from a page with a module script; it upgrades matching elements already in the page and any added later:
<script type="module" src="web-components/dui-tabs.js"></script>
Index
<dui-tabs>
No tabs element: one panel at a time, roving tabindex and arrow keys (APG Tabs). Upgrades a <nav> of in-page links and <section> panels; aria-current="true" on a link selects it on load.
Styles: tabs.css. Example: Tabs. Source: dui-tabs.js.
<dui-menu>
popovertarget opens the list, but there is no menu widget: arrow keys, Home/End, typeahead, opening on a chosen item (APG Menu Button).
Styles: menu-button.css. Example: Menu button. Source: dui-menu.js.
<dui-combobox>
<input list> suggests values, but the browser draws the popup: it cannot be styled, filters differently per engine and announces no result count. Builds an APG list autocomplete listbox from the <datalist> and keeps the same input (APG Combobox). See Combobox (typeahead) explainer.
Styles: combobox.css. Example: Typeahead. Source: dui-combobox.js.
<dui-toolbar>
No roving focus in HTML: one Tab stop with arrow keys between controls (APG Toolbar).
Styles: toolbar.css. Example: Toolbar. Source: dui-toolbar.js.
<dui-tooltip>
A popover cannot open on hover or focus yet. interestfor is the coming standard (Chromium only today); this element stands in until it is interoperable.
Styles: popover.css. Example: Popover. Source: dui-tooltip.js.
<dui-toaster>
A live region announces messages, but nothing builds a toast, adds its Dismiss button and moves focus sensibly when one goes away. See Toast explainer.
Styles: alerts.css. Example: Alerts. Source: dui-toaster.js.
<dui-app-shell>
A button cannot hide another element and keep aria-expanded in step, and a sidebar that is part of the page when wide must become a modal drawer only when the shell is narrow. Toggles hidden on a sidebar beside main, moves the one copy of a sidebar into a <dialog data-dialog="drawer"> (showModal()) while it is open on a narrow shell, and switches mode on the shell's own width (ResizeObserver); toggles are hidden until it upgrades. See App shell explainer.
Styles: app-shell.css (layout). Example: App shell. Source: dui-app-shell.js.
<dui-table>
A table cannot reorder its rows, and a checkbox cannot check its siblings, count them or be indeterminate from markup. Adds sortable column buttons with aria-sort (APG Sortable Table), a "select all" checkbox, the selection count and bulk-action enabling to a native <table>; without it the table is a plain table with ordinary checkboxes.
Styles: data-table.css. Example: Data table. Source: dui-table.js.
Successors
Each element is a bridge until the platform can do its job. Its header comment names the feature that would replace it and the condition that retires it; retiring one is a breaking change (Versioning, architecture).
| Element | Platform successor | Retire when |
|---|---|---|
<dui-tooltip> | interestfor | interestfor is Baseline newly available |
<dui-toolbar> | focusgroup | focusgroup is Baseline newly available |
<dui-tabs> | focusgroup for the arrow keys; no tabs element is proposed | The keys move to focusgroup; the element stays for selection |
<dui-menu> | The Open UI menu elements proposal | A native menu element is Baseline newly available |
<dui-combobox> | None for free text; customizable select for pick-one lists | Kept; pick-one uses move to <select> |
<dui-app-shell> | Container queries cover the layout; nothing moves one node into a modal | Kept |
<dui-table> | None proposed | Kept |
<dui-toaster> | None active | Kept |
Events
| Element | Event | When |
|---|---|---|
<dui-tabs> | dui-tabs-change | After the selected tab changes; event.detail is { tab, panel }. Bubbles. |
<dui-combobox> | dui-combobox-filter | On every input, before filtering; event.detail is { query }. Bubbles; cancelable: cancel it to load options yourself, then call setOptions(). |
<dui-combobox> | change (on the input) | When an option is accepted with Enter or a click, as a native control would. |
<dui-toaster> | dui-toaster-dismiss | Before a toast is removed. Bubbles; cancelable. |
<dui-app-shell> | dui-app-shell-toggle | After a sidebar is expanded, collapsed, opened or closed; event.detail is { sidebar, edge, expanded, drawer }. Bubbles. |
<dui-table> | dui-table-sort | Before the rows move; event.detail is { column, index, direction } (the <th>, its column index, "ascending" or "descending"). Bubbles; cancelable: cancel it to sort on the server, then set aria-sort and replace the rows yourself. |
<dui-menu>, <dui-toolbar> and <dui-tooltip> fire no events of their own (nor does <dui-table> for selection: listen for change on its checkboxes): listen for the native
click on items and controls, and the native toggle on popovers.