Accessibility
Accessibility principles, keyboard interaction models, and ARIA contracts in Moraine.
Moraine implements keyboard navigation, focus management, and ARIA relationships based on the W3C WAI-ARIA Authoring Practices. Applications still need accessible names, readable color contrast, and appropriate semantics for custom renderers and polymorphic elements.
Keyboard Interaction Models#
Moraine components follow established UI patterns for keyboard interaction:
Collection Navigation#
Tabs uses roving tabindex: the highlighted tab has tabindex="0", and other tab triggers have tabindex="-1". Select-family controls keep DOM focus on their trigger or input and identify the highlighted option through aria-activedescendant. Menus move focus between their items. These models support arrow navigation without adding every option to the page’s tab order:
| Key | Action |
|---|---|
| ↓ / → | Moves to the next item along the component’s navigation axis. |
| ↑ / ← | Moves focus to the previous item. |
| ↖ | Moves focus directly to the first enabled item. |
| ↘ | Moves focus directly to the last enabled item. |
| ↵ / Space | Activates or selects where supported; editable inputs retain normal text entry. |
Looping and activation depend on the component and its options. See each component’s keyboard documentation for orientation, disabled items, typeahead, and selection.
Overlay Dismissal#
Dismissible overlays (Dialog, Sheet, Drawer, Popover, Tooltip, HoverCard, DropdownMenu, ContextMenu, and select popups) close on Esc:
- Only the topmost active overlay handles Esc, so closing a nested overlay leaves its parent open.
- Esc is ignored while an IME composition is active.
- On overlays with
closeOnEscape, passcloseOnEscape={false}to block Esc dismissal;onClosePreventedreports the blocked attempt.
Focus Management#
Focus Trapping in Modals#
Modal surfaces (Dialog, Sheet, Drawer, and BaseDialog) trap keyboard focus inside their content while open:
- Tabbing past the last focusable element wraps back to the first.
- Outside content is hidden from assistive technology and page scroll is locked while open.
Popoveris non-modal and does not trap focus.- Passing
modal={false}on a modal surface disables focus trapping, initial focus movement, and focus restoration.
Focus Restoration#
- Modal overlays: Restore focus to their trigger after closing (or to the previously focused element). Pass
finalFocusto override the target element. - Non-modal floating overlays: Restore focus after keyboard dismissal, while allowing outside pointer presses to move focus naturally to the clicked target.
- Tooltips: Never move focus away from their trigger.
Initial Auto-Focus#
When a modal surface opens:
- It focuses the first
[autofocus]or[data-autofocus]descendant, falling back to the first focusable child, and otherwise the content container itself. - When opened by touch, it focuses the content container directly.
- Pass
initialFocusto target a specific element, orinitialFocus={false}to skip moving focus. - Menus and select-family controls manage their own highlighted item; tooltips never move focus into their content.
ARIA Attribute Contracts#
Moraine sets and updates these ARIA attributes from component state:
- State indication: Components maintain
aria-expanded="true|false"on triggers,aria-selected="true|false"on selection items, andaria-checked="true|false|mixed"on checkboxes. - Relationship wiring: Triggers and contents are linked through
aria-controlswith deterministic element IDs generated bycreateId. - Overlay names:
Dialog.ContentandSheet.Contentusetitleasaria-labelledby(unlessaria-labelis set) anddescriptionasaria-describedby.BaseDialog.Contentrendersrole="dialog"and needs anaria-labeloraria-labelledby. - Form association:
Fieldbinds itslabelto the registered control througharia-labelledby, and itshint,description,error, andhelptext througharia-describedby.hiddenLabelsupplies a visually hidden label whenlabelis empty. - Validation: When a field has an error, Moraine sets
aria-invalid="true"on the control and adds the visible error message toaria-describedby.
Screen Reader Considerations#
-
Semantic HTML: Moraine uses native controls such as
<button>and<input>alongside ARIA roles for custom widgets and overlay surfaces. When you use theasprop, the rendered element must provide the same semantics. -
Icon-only buttons: Provide an accessible name with
aria-label: -
Built-in labels: Accessible names that Moraine supplies, such as the
Dialogclose button, come from locale messages. Override them with a component’stranslationsprop orMoraineProvidermessages; see the Localization guide.