Soundor

Accessibility

Accessibility props for node components, and how runtimes present them.

The node components take React Native's accessibility props, so a custom-drawn control can tell screen readers what it is. Modal exposes accessibilityLabel for its dialog; Portal and FocusScope have no accessibility props of their own. Soundor owns these semantics: each runtime presents the same ones to its platform (ARIA in the browser, the platform's accessibility natively).

<Pressable
  accessibilityRole="adjustable"
  accessibilityLabel="Gain"
  accessibilityValue={{ min: -60, max: 12, now: gain, text: `${gain} dB` }}
  accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}
  onAccessibilityAction={(event) => {
    if (event.actionName === 'increment') setGain(gain + 0.5);
    if (event.actionName === 'decrement') setGain(gain - 0.5);
  }}
/>

The props

PropWhat it says
accessibletrue: one element, its descendants' text its label. false: the element itself is not perceived; its descendants still are.
accessibilityLabelWhat is read. By default, a text's text, or the text inside a button-like element.
accessibilityHintWhat acting on it does.
accessibilityKeyShortcutsThe keyboard shortcuts that act on it, as aria-keyshortcuts writes them: 'Control+Shift+S Meta+Shift+S' (Keyboard shortcuts).
accessibilityRolenone, text, image, button, link, adjustable, checkbox, switch, togglebutton, radio, radiogroup, progressbar, search, combobox, menu, menubar, menuitem, listbox, option, scrollbar, spinbutton, tab, tablist, header, summary, keyboardkey, timer, toolbar, alert, dialog.
accessibilityStatedisabled, readOnly, selected, checked (true, false, 'mixed'), busy, expanded.
accessibilityValuemin, max, now (fractional values are fine) and text ('-3.5 dB', read in place of the number).
accessibilityActionsThe actions it responds to: activate, increment, decrement, longpress, expand, collapse, escape, setValue, showContextMenu (Context menus), or custom names with a label.
onAccessibilityActionAn action asked of this element: event.actionName, and event.value for setValue. event.preventDefault() keeps the runtime's own response (a Pressable's press, focusing) from following.

Disabled and read-only controls

accessibilityState={{ disabled: true }} disables a node and its physical descendants, regardless of where they appear in the accessibility tree. A disabled target swallows presses, releases, clicks, context menus, and wheel input. These events do not bubble to a wrapper or go through to what is behind the target. Hover still works, so a tooltip can explain why a control is disabled.

Disabled nodes cannot take focus and are skipped by Tab. Disabling a focused node blurs it; disabling a pressed node cancels the gesture. Re-enabling a node does not restore its focus or the canceled gesture.

Use accessibilityState={{ readOnly: true }} for a value that can be read but not changed. It reports a read-only value to assistive technology without blocking focus, pointer, wheel, or keyboard input. For example, a read-only meter can still offer a “Copy value” context menu. The state does not make a text input non-editable; guard value changes in your control as needed.

Lists of choices

Give the container accessibilityRole="listbox" and each choice accessibilityRole="option". Set accessibilityState={{ selected: true }} on the chosen option and disabled: true on any unavailable option. Options are unselected by default and are read as one element, labelled by their content unless you provide accessibilityLabel. The roles describe the control; your component still manages selection and keyboard navigation.

PlatformHow choices are exposed
WebARIA listbox and option with aria-selected and aria-disabled.
WindowsUI Automation List and ListItem, with SelectionItem.IsSelected on each option.
LinuxAT-SPI list box and list item, with selectable and selected states.
macOSAppKit list and selectable rows; AppKit has no dedicated option role.
iOSUIKit list container. There is no option trait, so activatable choices use the button trait, and selected choices add the selected trait.

In Testing Library, use getByRole('listbox') and getByRole('option', { selected: true }).

Keyboard shortcuts

accessibilityKeyShortcuts tells assistive technology which shortcuts act on an element, as aria-keyshortcuts writes them: each shortcut its keys' KeyboardEvent.key names joined by +, modifiers first, the alternatives separated by spaces. It only tells: the shortcut is the app's to handle (Keyboard shortcuts), so give the shortcuts it handles on the platform it runs on.

<Pressable
  accessibilityKeyShortcuts={isMac ? 'Meta+Shift+S' : 'Control+Shift+S'}
  onPress={saveAs}
>
  <Text>Save as…</Text>
</Pressable>
PlatformHow shortcuts are exposed
Webaria-keyshortcuts.
WindowsUI Automation AcceleratorKey, as given.
LinuxAT-SPI's keyshortcuts attribute, as browsers give it.
macOSAppKit has no property for them outside its menus: the help text has them after the hint, Saves (⇧⌘S).
iOSThe same in the hint: UIKit has none outside its key commands.

In tests, a semantic node's keyShortcuts has them.

Announcements

announce(message, { priority }) from soundor:ui has a screen reader speak a message that is no element's label or value: what an action did when it changed nothing focused (a shortcut that copied a preset, or saved), or a change in a live control.

import { announce } from 'soundor:ui';

announce('Preset copied');
announce('Clipping', { priority: 'assertive' });

'polite' (the default) waits until the screen reader has said what it is saying; 'assertive' interrupts it, for what the user must know now. Keep announcements few and short: a meter announcing every value is noise. Nothing is spoken when no screen reader runs, and messages are not kept for one that starts later. An empty message is nothing; a message that is not a string, or another priority, throws a TypeError.

PlatformHow a message is spoken
WebAn entry added to an ARIA live region, aria-live polite or assertive.
WindowsA UI Automation notification event (Windows 10 1709 and later), ImportantAll when assertive.
LinuxAT-SPI's object:announcement, politeness polite or assertive (Orca speaks it).
macOSNSAccessibilityAnnouncementRequestedNotification, priority high when assertive, medium otherwise.
iOSUIAccessibilityAnnouncementNotification, queued unless assertive.

In tests, testView.announcements() lists what was announced.

Defaults

  • A View, scrolling or not, is not an element itself; what it contains is.
  • Text is read as its text (nested <Text> included, once). Accessibility props of a nested <Text> have no effect.
  • Image is decorative unless given a label, a role or accessible.
  • TextInput is a text field with its current text and placeholder.
  • Pressable is one element, a button unless given another role, labelled by its text; it offers activate (its onPress) and, with onLongPress, longpress (delivered to onLongPress as a longpress event whose pointerType is ''); disabled makes it disabled to assistive technology too (unless accessibilityState.disabled says otherwise).
  • TextInput offers activate (start editing: keyboard focus), focus and setValue (replace its text, firing input and change).
  • Modal is a modal dialog (accessibilityLabel names it): while it shows, only it is perceived, with the portals opened from inside it. With onRequestClose it offers escape (VoiceOver's scrub), which asks it to close like Escape does.

Context menus

An element offers a context menu only when its accessibilityActions include showContextMenu. An onContextMenu or onContextMenuCapture handler, on it or on an ancestor, never adds the action. The action keeps the element's role, value and other actions, and makes a plain View an element of its own (a group). Its default is a contextmenu event on the element, anchored at the bottom-left of its bounds (Context menus), so one onContextMenu serves the pointer, the keyboard and assistive technology. preventDefault() in onAccessibilityAction replaces that default:

<View
  focusable
  accessibilityLabel="Track 1"
  accessibilityActions={[{ name: 'showContextMenu' }]}
  onAccessibilityAction={(event) => {
    // Assistive technology gets a dialog instead; right-click, Shift+F10
    // and a touch hold still reach onContextMenu.
    if (event.actionName === 'showContextMenu') {
      event.preventDefault();
      openTrackDialog();
    }
  }}
  onContextMenu={openMenu}
/>

Each backend presents it as its platform's own action:

PlatformPresented as
macOSAXShowMenu (accessibilityPerformShowMenu)
WindowsUI Automation's IRawElementProviderSimple2::ShowContextMenu
LinuxAn AT-SPI Action named popup, described "Show context menu" (or the action's label)
iOSA VoiceOver action, "Show context menu" (or the action's label)
WebNo ARIA equivalent: a contextmenu the browser sends without a pointer or a key

macOS and Windows name the action themselves, so a label is not shown there. On the web, a contextmenu event the browser sends without a pointer, and not for a key or press Soundor already made a request for (a screen reader's command, such as VoiceOver's VO-Shift-M), is this action: it is asked of the nearest element offering showContextMenu, and its default is the contextmenu event. Without such an element it is an ordinary request to the node it targets.

Moving a screen reader's cursor does not move keyboard focus; only an explicit focus request does (or activating a text input), and only to a focusable element. A node with tabStop={false} is one: it leaves the Tab order only, and its role, name and state describe it as before (Roving focus).

Examples

// A button: its text is its label; assistive technology's "activate" is onPress.
<Pressable onPress={save}>
  <Text>Save preset</Text>
</Pressable>

// A toggle: a switch with its state.
<Pressable
  accessibilityRole="switch"
  accessibilityLabel="Bypass"
  accessibilityState={{ checked: bypassed }}
  onPress={() => setBypassed(!bypassed)}
/>

// An adjustable gain control. Every input changes the same state through
// one function; the accessibility value is that state, not a copy.
<View
  focusable
  accessibilityRole="adjustable"
  accessibilityLabel="Gain"
  accessibilityValue={{ min: -60, max: 12, now: gain, text: `${gain.toFixed(1)} dB` }}
  accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }, { name: 'setValue' }]}
  onAccessibilityAction={(event) => {
    if (event.actionName === 'increment') change(gain + 0.5);
    if (event.actionName === 'decrement') change(gain - 0.5);
    if (event.actionName === 'setValue') change(Number(event.value));
  }}
  onKeyDown={(event) => {
    if (event.key === 'ArrowUp') change(gain + 0.5);
    if (event.key === 'ArrowDown') change(gain - 0.5);
  }}
  onPointerMove={drag}
/>

// A text input: labelled; its text is read as its value.
<TextInput accessibilityLabel="Preset name" value={name} onChangeText={setName} />

// A modal dialog: only it is read while open; escape asks it to close.
<Modal visible={open} onRequestClose={close} accessibilityLabel="Settings">
  {/* ... */}
</Modal>

The primitives example has a complete knob (GainKnob).

How it works

Soundor owns a platform-neutral semantic tree. It is built from the view's nodes and their accessibility, by the same rules in every runtime. The runtime's platform backend then presents it:

PlatformBackend
WebARIA on the DOM elements that draw nodes
WindowsNative UI Automation
LinuxNative AT-SPI over GDBus
AndroidNo native runtime view yet
macOSNative NSAccessibility
iOSSoundor's VoiceOver bridge (no iOS runtime yet)
  • Not tied to a framework: the semantics do not come from a plugin framework or Skia. A plugin framework only tells the backend which native view the surface is in, and where. A plugin's accessibility code is the same whatever framework hosts it.

  • Three trees: the render tree (nodes, and where they draw: a portal's content is under overlayRoot), the keyboard focus structure (FocusScopes, which follow React), and the semantic tree (what a screen reader perceives) often look alike but differ:

    • a button's text is not an element of its own;
    • a portal opened inside a modal is read inside it, wherever it draws (its overlay entry's accessibilityParent);
    • a modal hides the rest from the semantic tree while keyboard focus is trapped by its own FocusScope.

    Closing a modal restores keyboard focus (the FocusScope) and the accessibility context (the semantic tree) separately.

  • Coordinates: an element's bounds are the view's logical pixels, like getBoundingClientRect(). Each backend converts them to its platform's screen coordinates itself. Pointer events also provide screenX/screenY in editor logical pixels (coordinates); those do not replace the backend's conversion of accessibility bounds.

  • Cost: nothing is computed until assistive technology is listening. After that, each frame sends only the elements that changed.

Linux needs the system GIO library (libgio-2.0.so.0). Text caret positions, selections and character geometry are not part of the native semantic contract. See the Linux adapter notes for its capabilities and current verification limits.

See the native accessibility reference for the rules in detail and the backends, and its Apple bridge notes for how the macOS and iOS bridges stay safe in a plugin host.

On this page