Chapter 18
Accessibility
PixiFormUI exposes the form to assistive technology in two layers, and neither one ever contains a field value:
- The accessibility outline: a hidden DOM copy of the form's structure (
role="form"named after the title). It holds headings and paragraphs, labelled groups (role="group", like<fieldset>/<legend>), and one element per control with its role, name and states. Screen-reader users can browse it like a normal page: read headings, list form fields, jump between groups. Each element sits over its control, so touch exploration with VoiceOver or TalkBack finds it where the user sees it. Focusing or activating an item focuses the real control; buttons, checkboxes, switches and group headers are activated too. - The keyboard proxy: the single hidden input that holds keyboard focus. It takes the focused control's role, name and states.
| Feature | Implementation |
|---|---|
| Name, role, state | aria-label is the plain label. Required and invalid are the aria-required and aria-invalid states, plus aria-checked, aria-expanded, aria-valuenow and so on. |
| Help and errors | Linked descriptions: aria-describedby points to the error and help/ⓘ text, and aria-errormessage to the error. Screen readers read them after the name instead of repeating one long label. |
| Groups | FieldGroup → role="group" labelled by its title. Collapsible headers are buttons with aria-expanded. The title is announced when focus enters the group. |
| Composite controls | PhoneInput is a group named "Phone" containing its country-code and number parts. |
| Keyboard | Full operation. Tab from the page lands on the first control and Shift+Tab from after the form on the last; Tab leaves at the ends. F1 toggles the ⓘ tooltip, and Esc closes it. |
| Announcements | An aria-live region carries validation summaries, toasts and "Caps Lock is on". Values are never announced. |
| Canvas | aria-hidden="true", since the pixels are decorative for assistive technology. |
18.1 System settings (followed automatically)#
| OS / browser setting | What PixiFormUI does |
|---|---|
Windows High Contrast (forced-colors: active) |
Repaints the canvas with the user's actual system colours (Canvas, CanvasText, Highlight, GrayText…), with thicker borders and focus rings. The browser can't recolour canvas pixels itself. |
More contrast (prefers-contrast: more) |
Darker borders, secondary text and placeholders, 2 px borders, stronger focus ring. |
Reduced motion (prefers-reduced-motion: reduce) |
Animations snap, the caret stops blinking, and the OTP field doesn't shake. |
| Browser zoom | The canvas re-renders at the new device pixel ratio (up to 3×), so text stays sharp at 200%+. |
Override or extend them per form:
const ui = new FormUI(app, {
theme,
a11y: {
label: 'Create account', // accessible form name (default: first heading)
textScale: 1.25, // larger text and controls (0.75–2)
highContrast: 'auto', // 'auto' | 'on' | 'off'
reducedMotion: 'auto', // 'auto' | 'on' | 'off'
forcedColors: 'auto', // 'auto' | 'off'
followZoom: true,
outline: true, // the hidden DOM outline
},
});
ui.setA11y({ textScale: 1.5 }); // e.g. from a "Larger text" toggle
ui.activePrefs; // { forcedColors, highContrast, reducedMotion, textScale }
ui.on('a11ychange', (prefs) => {});
With mountPixiForm, pass the same object as config.a11y. The theme helpers are exported if you want to build
themes yourself: scaleTheme, increaseContrast, systemColorTheme, adaptTheme.
18.2 Custom controls#
Your control gets all of this by extending Control. Override these when needed:
ariaRole()andariaLabel(): the role and the name only (for example "Rating, 3 of 5 stars"). Don't append errors or help text.ariaState(): ARIA states such as{ 'aria-valuenow': '3' }.ariaDescription():{ help, error }. The default useshelperText,infoand the current error.activate(): what a screen-reader "click" does. The default presses Space for checkbox/switch roles and Enter otherwise. Text fields just take focus.
Static widgets appear in the outline by implementing a11yText(): { text, heading }, and containers appear as
groups by implementing a11yGroup() (see Label and FieldGroup).
18.3 Testing#
axe and Lighthouse can't see inside a canvas, but they can audit the outline. Browser tests can assert on it directly:
const names = await page.$$eval('.pixiform-a11y [role]', (els) => els.map((e) => [e.getAttribute('role'), e.getAttribute('aria-label')]));
// Focus a field the way a screen reader does:
await page.$eval('.pixiform-a11y [aria-label="Email"]', (el) => el.focus());
Remaining limitation: screen readers can't read back what was typed into text fields, because values never enter the DOM. Labels, states and errors are all available. If your audience needs read-back, consider an HTML alternative for non-sensitive forms.