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
| Prop | What it says |
|---|---|
accessible | true: one element, its descendants' text its label. false: the element itself is not perceived; its descendants still are. |
accessibilityLabel | What is read. By default, a text's text, or the text inside a button-like element. |
accessibilityHint | What acting on it does. |
accessibilityKeyShortcuts | The keyboard shortcuts that act on it, as aria-keyshortcuts writes them: 'Control+Shift+S Meta+Shift+S' (Keyboard shortcuts). |
accessibilityRole | none, 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. |
accessibilityState | disabled, readOnly, selected, checked (true, false, 'mixed'), busy, expanded. |
accessibilityValue | min, max, now (fractional values are fine) and text ('-3.5 dB', read in place of the number). |
accessibilityActions | The actions it responds to: activate, increment, decrement, longpress, expand, collapse, escape, setValue, showContextMenu (Context menus), or custom names with a label. |
onAccessibilityAction | An 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.
| Platform | How choices are exposed |
|---|---|
| Web | ARIA listbox and option with aria-selected and aria-disabled. |
| Windows | UI Automation List and ListItem, with SelectionItem.IsSelected on each option. |
| Linux | AT-SPI list box and list item, with selectable and selected states. |
| macOS | AppKit list and selectable rows; AppKit has no dedicated option role. |
| iOS | UIKit 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>| Platform | How shortcuts are exposed |
|---|---|
| Web | aria-keyshortcuts. |
| Windows | UI Automation AcceleratorKey, as given. |
| Linux | AT-SPI's keyshortcuts attribute, as browsers give it. |
| macOS | AppKit has no property for them outside its menus: the help text has them after the hint, Saves (⇧⌘S). |
| iOS | The 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.
| Platform | How a message is spoken |
|---|---|
| Web | An entry added to an ARIA live region, aria-live polite or assertive. |
| Windows | A UI Automation notification event (Windows 10 1709 and later), ImportantAll when assertive. |
| Linux | AT-SPI's object:announcement, politeness polite or assertive (Orca speaks it). |
| macOS | NSAccessibilityAnnouncementRequestedNotification, priority high when assertive, medium otherwise. |
| iOS | UIAccessibilityAnnouncementNotification, 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. Textis read as its text (nested<Text>included, once). Accessibility props of a nested<Text>have no effect.Imageis decorative unless given a label, a role oraccessible.TextInputis a text field with its current text and placeholder.Pressableis one element, abuttonunless given another role, labelled by its text; it offersactivate(itsonPress) and, withonLongPress,longpress(delivered toonLongPressas alongpressevent whosepointerTypeis'');disabledmakes it disabled to assistive technology too (unlessaccessibilityState.disabledsays otherwise).TextInputoffersactivate(start editing: keyboard focus),focusandsetValue(replace its text, firinginputandchange).Modalis a modaldialog(accessibilityLabelnames it): while it shows, only it is perceived, with the portals opened from inside it. WithonRequestCloseit offersescape(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:
| Platform | Presented as |
|---|---|
| macOS | AXShowMenu (accessibilityPerformShowMenu) |
| Windows | UI Automation's IRawElementProviderSimple2::ShowContextMenu |
| Linux | An AT-SPI Action named popup, described "Show context menu" (or the action's label) |
| iOS | A VoiceOver action, "Show context menu" (or the action's label) |
| Web | No 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:
| Platform | Backend |
|---|---|
| Web | ARIA on the DOM elements that draw nodes |
| Windows | Native UI Automation |
| Linux | Native AT-SPI over GDBus |
| Android | No native runtime view yet |
| macOS | Native NSAccessibility |
| iOS | Soundor'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 providescreenX/screenYin 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.