diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index efff4e5..b69b49f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -7,6 +7,10 @@ - [ ] `yarn check` passes. - [ ] **Accessibility:** new or changed UI has a role and name, a 44dp target, keyboard access, scaling text, and theme colors only; its states have stories (docs/accessibility.md). +- [ ] **Assistive technology:** if this adds a component or changes a role, name, state, keyboard + handling or announcement, the component's `accessibility.md` is updated and I ran the + manual pass and recorded it in docs/assistive-technology-testing.md (or asked for help + here). - [ ] **Theming:** no literal colors or sizes; new color pairings are in `contrastRequirements`. - [ ] **Public API:** if the API snapshot changed, the change is intended and there is a changeset (`yarn changeset`). diff --git a/AGENTS.md b/AGENTS.md index 236838f..a38923a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,8 +26,15 @@ Expo and Expo web (ADR 0002). Nothing imports an app or `e2e/`. ## Where new code goes -- **A new component:** `yarn new:component `. It writes the component, test, story and - index in `packages/ui/src/components//` and exports it. Then build it from primitives. +- **A new component:** `yarn new:component `. It writes the component, test, story, + index and accessibility spec stub in `packages/ui/src/components//` and exports it. Then + build it from primitives. +- **A component's accessibility spec:** `accessibility.md` beside the component: role, name and + states (web and native), keyboard, focus, expected announcements and known issues, based on the + matching WAI-ARIA APG pattern. A gap from the pattern goes under known issues. +- **Manual assistive technology results:** a section per component in + [docs/assistive-technology-testing.md](docs/assistive-technology-testing.md). A new component, + or a change to a role, state, keyboard handling or announcement, needs a manual pass there. - **A new color:** add a semantic name to `ThemeColors` in `src/theme/colors.ts` and give it a value in every theme. If components render it on or under another color, add the pairing to `contrastRequirements` in `src/theme/contrast-audit.ts`. Never put a literal color in a @@ -47,6 +54,8 @@ Expo and Expo web (ADR 0002). Nothing imports an app or `e2e/`. - Accessibility is a requirement, not polish. Every control has an accessible name and role, a 44dp touch target, text that scales to 200%, and a visible keyboard focus ring. Both themes meet WCAG 2.2 AA contrast. The checks are in [docs/accessibility.md](docs/accessibility.md). +- Every component has an accessibility spec and a manual results section; changing what it + announces or how it handles keys means updating the spec and rerunning the manual pass. - Every component has a story. Stories are test fixtures: Jest renders each one in both themes for the accessibility contract, and Playwright runs axe and screenshots on each one. - Coverage thresholds in `packages/*/jest.config.cjs` are 100% and only go up. diff --git a/docs/accessibility.md b/docs/accessibility.md index 8fb8389..a8a5603 100644 --- a/docs/accessibility.md +++ b/docs/accessibility.md @@ -4,6 +4,12 @@ wolf-ui targets **WCAG 2.2 level AA** on iOS, Android and the web. Accessibility "done", not a later pass: every requirement below has a check that fails the build (ADR 0008). Checks that cannot run without a device are listed at the end with their planned guard. +What each component should do for a screen reader or keyboard user is written in its spec, +`accessibility.md` beside the component (role, name and states, keyboard, focus, expected +announcements, known issues). What real assistive technology did when a person last tried it is +recorded in [assistive-technology-testing.md](assistive-technology-testing.md), with the +supported matrix and when a manual pass is required. + ## How it is checked 1. **Types make the accessible path the only path.** `Button` takes its label as `children: @@ -54,7 +60,9 @@ string`, `TextInput` requires `label`, `Text` requires a `variant`, an `Icon` is - **Screen reader output on devices** (VoiceOver on iOS, TalkBack): planned as Maestro flows against on-device Storybook (engineering-standards 6.2). The web build is covered by the - virtual reader and VoiceOver on macOS; check new components on a device by hand until then. + virtual reader and VoiceOver on macOS; until the device flows land, check new components on a + device by hand with the matrix and process in + [assistive-technology-testing.md](assistive-technology-testing.md). - **What the virtual reader gets wrong**: it reads inside a progressbar (the spinner's "graphics-document") and a busy button, which real readers treat as one item, and it reads a password field's value aloud. These lines in the transcripts are expected (ADR 0010). @@ -65,6 +73,10 @@ string`, `TextInput` requires `label`, `Text` requires a `variant`, an `Icon` is ## Checklist for a new component +- [ ] Its `accessibility.md` is filled in from the matching APG pattern, with every gap under + known issues (`src/__contracts__/component-structure.test.ts` checks it exists). +- [ ] It has a results section in [assistive-technology-testing.md](assistive-technology-testing.md) + and has had a manual pass on every row of the matrix. - [ ] It has a role and an accessible name, from a required prop where possible. - [ ] It is reachable and operable by keyboard on the web. - [ ] Every interactive part is at least 44dp tall (use `minTouchTarget` and `hitSlop`). diff --git a/docs/assistive-technology-testing.md b/docs/assistive-technology-testing.md new file mode 100644 index 0000000..f0cfca2 --- /dev/null +++ b/docs/assistive-technology-testing.md @@ -0,0 +1,139 @@ +# Assistive technology testing + +Automation proves that every story has names, roles, states, contrast, touch targets and +keyboard access ([accessibility.md](accessibility.md)). It cannot prove that a person using a +screen reader understands a component and can use it. That needs a person with the real +assistive technology (AT). This page says which AT wolf-ui supports, when a manual test is +required, how to run one, and what each component got last time. + +What a component should do is written in its spec, `accessibility.md` beside the component: + +| Component | Spec | +| --------- | ------------------------------------------------------------------------------------------------- | +| Button | [components/Button/accessibility.md](../packages/ui/src/components/Button/accessibility.md) | +| Card | [components/Card/accessibility.md](../packages/ui/src/components/Card/accessibility.md) | +| Icon | [components/Icon/accessibility.md](../packages/ui/src/components/Icon/accessibility.md) | +| Spinner | [components/Spinner/accessibility.md](../packages/ui/src/components/Spinner/accessibility.md) | +| Stack | [components/Stack/accessibility.md](../packages/ui/src/components/Stack/accessibility.md) | +| TextInput | [components/TextInput/accessibility.md](../packages/ui/src/components/TextInput/accessibility.md) | + +`src/__contracts__/component-structure.test.ts` fails if a component folder has no spec, and +`yarn new:component` writes a stub. + +## Supported matrix + +| ID | Assistive technology | Browser or runtime | Platform | What it covers | +| ------ | -------------------- | ---------------------------------------------- | ---------------- | ------------------------------------------------------ | +| VO-mac | VoiceOver | Safari, web Storybook | macOS (latest) | the web build with Apple's reader | +| VO-iOS | VoiceOver | on-device Storybook (Expo) | iOS (latest) | the native iOS build | +| TB | TalkBack | Chrome, web Storybook, and on-device Storybook | Android (latest) | the native Android build, and the web build on Android | +| NVDA | NVDA | Chrome or Firefox, web Storybook | Windows 11 | the web build with the most used desktop reader | +| KB | Keyboard only | Chrome, Safari or Firefox | any desktop | Tab order, activation keys, focus visibility | + +"Latest" means the current major release when the test is run; record the exact version in the +results. JAWS, Narrator, Orca, Switch Control, Voice Control and magnifiers are not in the matrix +yet. Issues reported with them are still accepted. + +## When a manual test is required + +A pull request needs a manual AT pass, on every row of the matrix, when it: + +1. **adds a component**, or +2. **changes a component's role, name source, states, keyboard handling or announcements**: for + example a new `aria-*` or `accessibility*` prop, a live region, a changed label, a new key, + a change to what is focusable, or a changed transcript in `e2e/__transcripts__/`. + +Changes to colours, spacing or layout only, or to tests and docs only, do not need one. If in +doubt, test. The pull request template has a checkbox for it. The author runs the test, or asks +for help in the pull request when they do not have a device; a pull request that needs a test is +not merged until the results are recorded. + +A full pass of the matrix on every component is also due before each major release. + +## How to test + +1. Build the branch: `yarn storybook:web` for the web rows, `yarn storybook:ios` or + `yarn storybook:android` for the device rows. +2. Open the component's spec and go through each story. +3. For each row of the matrix, check: + - every item in the spec's "Expected announcements" is heard, with nothing extra (no "not + busy", no unnamed "button" or "image"); + - every key in the spec's "Keyboard" table does what it says (a keyboard or switch on + devices: VoiceOver and TalkBack gestures for the reader rows); + - focus is visible and goes where the spec says; + - with the largest text size, the component still reads and works. +4. Record one row per AT in the component's table below: the AT and its version, the browser or OS + version in notes, the date (YYYY-MM-DD), and the result. +5. If anything differs from the spec, record it as **Fail** or **Partial**, open an issue, and + either fix the component or, if the behaviour is acceptable, add it to the spec's known issues. + +Results: **Pass** (as specified), **Partial** (usable, with a difference noted), **Fail** (a +user of that AT cannot understand or use it), **Not yet tested**. Replace a component's row for an +AT when it is retested; git keeps the history. + +## Results + +### Button + +| AT | Version | Date | Result | Notes | +| ------ | ------- | ---- | -------------- | ----- | +| VO-mac | - | - | Not yet tested | | +| VO-iOS | - | - | Not yet tested | | +| TB | - | - | Not yet tested | | +| NVDA | - | - | Not yet tested | | +| KB | - | - | Not yet tested | | + +### Card + +| AT | Version | Date | Result | Notes | +| ------ | ------- | ---- | -------------- | ----- | +| VO-mac | - | - | Not yet tested | | +| VO-iOS | - | - | Not yet tested | | +| TB | - | - | Not yet tested | | +| NVDA | - | - | Not yet tested | | +| KB | - | - | Not yet tested | | + +### Icon + +| AT | Version | Date | Result | Notes | +| ------ | ------- | ---- | -------------- | ----- | +| VO-mac | - | - | Not yet tested | | +| VO-iOS | - | - | Not yet tested | | +| TB | - | - | Not yet tested | | +| NVDA | - | - | Not yet tested | | +| KB | - | - | Not yet tested | | + +### Spinner + +| AT | Version | Date | Result | Notes | +| ------ | ------- | ---- | -------------- | ----- | +| VO-mac | - | - | Not yet tested | | +| VO-iOS | - | - | Not yet tested | | +| TB | - | - | Not yet tested | | +| NVDA | - | - | Not yet tested | | +| KB | - | - | Not yet tested | | + +### Stack + +| AT | Version | Date | Result | Notes | +| ------ | ------- | ---- | -------------- | ----- | +| VO-mac | - | - | Not yet tested | | +| VO-iOS | - | - | Not yet tested | | +| TB | - | - | Not yet tested | | +| NVDA | - | - | Not yet tested | | +| KB | - | - | Not yet tested | | + +### TextInput + +| AT | Version | Date | Result | Notes | +| ------ | ------- | ---- | -------------- | ----- | +| VO-mac | - | - | Not yet tested | | +| VO-iOS | - | - | Not yet tested | | +| TB | - | - | Not yet tested | | +| NVDA | - | - | Not yet tested | | +| KB | - | - | Not yet tested | | + +## Adding a component + +`yarn new:component` writes the spec stub. Before the component's pull request is merged, fill +in the spec, add a section here with a "Not yet tested" row per AT, and run the manual pass. diff --git a/docs/engineering-standards.md b/docs/engineering-standards.md index c6f013e..e308812 100644 --- a/docs/engineering-standards.md +++ b/docs/engineering-standards.md @@ -41,10 +41,12 @@ no Expo code loaded (ADR 0002). `apps/storybook` bundles it with Expo for iOS, A ### 1.3 Every component has the same shape -`packages/ui/src/components//` holds `.tsx`, `.test.tsx`, `.stories.tsx` -and `index.ts`, the stories are titled `Components/`, and `components/index.ts` exports -it. **Guard:** `src/__contracts__/component-structure.test.ts`. `yarn new:component` writes all of -it (4.4). +`packages/ui/src/components//` holds `.tsx`, `.test.tsx`, `.stories.tsx`, +`index.ts` and an `accessibility.md` spec with every section, the stories are titled +`Components/`, `components/index.ts` exports it, and +`docs/assistive-technology-testing.md` has a results section for it. **Guard:** +`src/__contracts__/component-structure.test.ts`. `yarn new:component` writes all of it but the +results section (4.4). The package's public API is snapshotted. **Guard:** `src/__contracts__/public-api.test.ts`; an API change is a snapshot change in the diff. diff --git a/packages/ui/src/__contracts__/component-structure.test.ts b/packages/ui/src/__contracts__/component-structure.test.ts index 7c8edac..beb025a 100644 --- a/packages/ui/src/__contracts__/component-structure.test.ts +++ b/packages/ui/src/__contracts__/component-structure.test.ts @@ -1,10 +1,22 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; -// docs/engineering-standards.md 1.3: every component is a folder with the same four files, so -// nothing ships untested, without a story, or outside the public entry. `yarn new:component` -// writes all of them. +// docs/engineering-standards.md 1.3: every component is a folder with the same five files, so +// nothing ships untested, without a story, without an accessibility spec, or outside the public +// entry. `yarn new:component` writes all of them. docs/assistive-technology-testing.md keeps a +// manual results table for each component. const componentsDir = join(__dirname, '..', 'components'); +const atTesting = readFileSync( + join(__dirname, '..', '..', '..', '..', 'docs', 'assistive-technology-testing.md'), + 'utf8', +); +const specSections = [ + '## Role, name and states', + '## Keyboard', + '## Focus', + '## Expected announcements', + '## Known issues', +]; const components = readdirSync(componentsDir, { withFileTypes: true }) .filter((entry) => entry.isDirectory()) .map((entry) => entry.name); @@ -21,10 +33,28 @@ describe.each(components)('%s', (name) => { expect(name).toMatch(/^[A-Z][A-Za-z0-9]*$/); }); - it.each([`${name}.tsx`, `${name}.test.tsx`, `${name}.stories.tsx`, 'index.ts'])('has %s', (f) => { + it.each([ + `${name}.tsx`, + `${name}.test.tsx`, + `${name}.stories.tsx`, + 'index.ts', + 'accessibility.md', + ])('has %s', (f) => { expect(existsSync(file(f))).toBe(true); }); + it('has an accessibility spec with every section (docs/accessibility.md)', () => { + const spec = readFileSync(file('accessibility.md'), 'utf8'); + expect(spec.startsWith(`# ${name}: accessibility spec\n`)).toBe(true); + for (const section of specSections) { + expect(spec).toContain(`\n${section}\n`); + } + }); + + it('has a results table in docs/assistive-technology-testing.md', () => { + expect(atTesting).toContain(`\n### ${name}\n`); + }); + it('is exported from components/index.ts', () => { expect(barrel).toContain(`export * from './${name}';`); }); diff --git a/packages/ui/src/components/Button/accessibility.md b/packages/ui/src/components/Button/accessibility.md new file mode 100644 index 0000000..58865b9 --- /dev/null +++ b/packages/ui/src/components/Button/accessibility.md @@ -0,0 +1,69 @@ +# Button: accessibility spec + +Pattern: [WAI-ARIA APG Button](https://www.w3.org/WAI/ARIA/apg/patterns/button/). Manual results: +[docs/assistive-technology-testing.md](../../../../../docs/assistive-technology-testing.md#button). + +## Role, name and states + +| Aspect | Web (React Native Web output) | iOS / Android (React Native props) | +| -------- | ------------------------------------------------------------------- | ---------------------------------------------------------- | +| Role | `role="button"` on a `div` | `role="button"` | +| Name | Text content: the `children` string | The `children` string, read from the label `Text` | +| Hint | none (React Native Web drops `accessibilityHint`) | `accessibilityHint` when passed | +| Disabled | `aria-disabled="true"`, `tabindex="-1"` | `aria-disabled`, `disabled` (presses ignored) | +| Loading | `aria-busy="true"`, `aria-disabled="true"`; spinner named "Loading" | `aria-busy`, `aria-disabled`; spinner labelled "Loading" | +| Icons | `iconStart` / `iconEnd` are `aria-hidden`; they never join the name | `importantForAccessibility="no-hide-descendants"` on icons | + +The name comes from a required `children: string`, so a button cannot be unnamed and its visible +label always matches its accessible name (WCAG 2.5.3). + +## Keyboard + +| Key | Behaviour | +| ----------- | ---------------------------------------------------------------- | +| Tab | Moves focus to the button, in DOM order. Skips it when disabled. | +| Shift + Tab | Moves focus to the previous focusable element. | +| Enter | Calls `onPress`. Nothing when disabled or loading. | +| Space | Calls `onPress`. Nothing when disabled or loading. | + +Enter and Space come from React Native Web's press responder for `role="button"`. +`e2e/tests/keyboard.spec.ts` checks Tab and Enter. + +## Focus + +- A 2px ring in the theme's `focusRing` color, offset 2px, on keyboard focus only (the + `Pressable` primitive, `:focus-visible` on the web). A mouse click leaves no ring. +- On iOS and Android every focus shows the ring, since focus only moves by keyboard, switch + control or remote. +- Pressing the button does not move focus. + +## Expected announcements + +Every reader must say the name, the role and any state. Word order and the state words differ by +reader and version, so manual results record what was really said. + +| State | Must hear | VoiceOver (macOS, iOS) | TalkBack | NVDA | +| -------- | --------------------------------- | ---------------------- | ----------------------- | -------------------------- | +| Default | "Continue", button | "Continue, button" | "Continue, button" | "Continue, button" | +| Disabled | "Continue", button, disabled | "... dimmed" | "... disabled" | "... unavailable" | +| Loading | "Continue", button, busy/disabled | "... dimmed" (+ busy) | "... disabled" (+ busy) | "... unavailable" (+ busy) | + +A reader must not say "not busy", and must not read the icons. The virtual reader's web +transcripts (`e2e/__transcripts__/components-button--*.txt`) read +"button, Continue" and, while loading, "button, Continue, busy, disabled". + +## Known issues + +- **Disabled buttons leave the Tab order on the web.** React Native Web sets `tabindex="-1"` + when `disabled`, so keyboard and screen reader users tabbing through a form do not find a + disabled submit button. APG allows this, but it hides why an action is unavailable. A loading + button also leaves the Tab order; whether focus survives a focused button switching to loading + has not been tested. +- **The spinner is a nested `progressbar`.** While loading, a progressbar sits inside the button. + ARIA treats a button's children as presentational, so real readers should ignore it, but on iOS + and Android the spinner's "Loading" label may be read before the button's name (shown above as + expected). Not yet confirmed on devices. +- **No `aria-pressed` or `aria-expanded`.** Button has no toggle or disclosure mode; build those + as separate components rather than passing raw ARIA props. +- **`accessibilityHint` is native only.** React Native Web drops it, so a hint is not read on the + web. Do not put information only in the hint. diff --git a/packages/ui/src/components/Card/accessibility.md b/packages/ui/src/components/Card/accessibility.md new file mode 100644 index 0000000..fc69e97 --- /dev/null +++ b/packages/ui/src/components/Card/accessibility.md @@ -0,0 +1,52 @@ +# Card: accessibility spec + +Pattern: no APG pattern. A Card is a visual surface, not a widget or landmark. When a card needs +to be a landmark, the app gives it one (see below). Manual results: +[docs/assistive-technology-testing.md](../../../../../docs/assistive-technology-testing.md#card). + +## Role, name and states + +| Aspect | Web (React Native Web output) | iOS / Android (React Native props) | +| ------ | ----------------------------------------------------------------- | ---------------------------------- | +| Role | none: a plain `div` | none: a plain `View` | +| Name | none | none | +| States | none | none | +| Props | any `Box` prop, so `role`, `aria-*` and `accessible` pass through | same | + +Card's content is read in order as if the card were not there. That is correct for a visual +grouping. Two things are the app's job: + +- **Headings.** A title inside a card is only a heading if it is one: pass `role="heading"` (and + `aria-level` on the web) to the title `Text`. The `heading3` text variant is a size, not a role. +- **Grouping.** To make the card one stop for VoiceOver and TalkBack, pass `accessible` and an + `accessibilityLabel`; on the web, `role="group"` or `role="region"` with `aria-label`. + +## Keyboard + +| Key | Behaviour | +| --- | ----------------------------------------------------------------- | +| Tab | Moves to the focusable children in order. The card is not a stop. | + +## Focus + +Never takes focus. A pressable card is not supported: wrap the action in a `Button` inside the +card instead, so the card does not become one large control with a long name. + +## Expected announcements + +| Screen reader | Must hear | +| ------------- | -------------------------------------------------------------------------------------------------------------------- | +| All | The children in order, with no extra words for the card: "Weekly summary", "You completed 12 of 14 tasks this week." | + +The virtual reader's transcripts (`e2e/__transcripts__/components-card--*.txt`) read exactly those two lines for every variant. + +## Known issues + +- **The story's title is not a heading.** The stories use `Text variant="heading3"` with no + heading role, so screen reader users cannot jump to it. The component is correct; the stories + and docs should show the heading role. +- **Variants are visual only.** `elevated`, `outlined` and `filled` differ in shadow, border and + background. Nothing about the variant is announced, and nothing should be. +- **Shadow-only edge.** The `elevated` card is separated from the page by its shadow; in forced + colours mode (Windows High Contrast) shadows are removed and the card edge may disappear. Not + yet tested. diff --git a/packages/ui/src/components/Icon/accessibility.md b/packages/ui/src/components/Icon/accessibility.md new file mode 100644 index 0000000..00455c8 --- /dev/null +++ b/packages/ui/src/components/Icon/accessibility.md @@ -0,0 +1,52 @@ +# Icon: accessibility spec + +Pattern: no APG widget pattern; an icon is an image. It follows the +[WAI images tutorial](https://www.w3.org/WAI/tutorials/images/) (decorative vs informative) and +the ARIA `img` role. Manual results: +[docs/assistive-technology-testing.md](../../../../../docs/assistive-technology-testing.md#icon). + +## Role, name and states + +| Aspect | Web (React Native Web output) | iOS / Android (React Native props) | +| ---------------------- | ----------------------------------------- | ---------------------------------------------------------------- | +| Decorative (no label) | `aria-hidden="true"` on the wrapper `div` | `aria-hidden`, `importantForAccessibility="no-hide-descendants"` | +| Informative (labelled) | `role="img"`, `aria-label` = the label | `accessible`, `role="img"`, `accessibilityLabel` = the label | +| States | none | none | + +An icon is decorative unless it gets an `accessibilityLabel`, so the safe default is silence. The +contract test fails a story that has `role="img"` without a name (WCAG 1.1.1). + +## Keyboard + +| Key | Behaviour | +| --- | -------------------------------------------------------------------------- | +| - | None. An icon is never focusable. Put it inside a `Button` to make it act. | + +## Focus + +Never takes focus. A labelled icon is reachable only with a screen reader's reading cursor +(VoiceOver VO + arrows, TalkBack swipe, NVDA browse mode), not with Tab. + +## Expected announcements + +| Use | Must hear | +| ------------------------ | ---------------------------------------------------------------------- | +| Decorative | nothing; the reader skips it | +| Labelled, e.g. "Warning" | "Warning", image (VoiceOver "image", TalkBack "image", NVDA "graphic") | +| Inside a `Button` | nothing; only the button's text is the name | + +The virtual reader's transcripts (`e2e/__transcripts__/components-icon--*.txt`): the Default story is empty, Labelled reads "image, Warning", and the All story +reads only the caption under each icon. + +## Known issues + +- **The SVG itself has no role or title.** The name sits on the wrapper `View`; the inner + `react-native-svg` `` has no `role` or ``. Readers use the wrapper, but some + browser and reader pairs may also expose the SVG as an unnamed graphic. Needs manual testing + with NVDA. +- **No tooltip or visible text.** A labelled icon's meaning is only available to screen readers + and to sighted users who recognise the shape. Pair meaningful icons with visible text where you + can. +- **Windows High Contrast / forced colours.** Icons are drawn with a theme colour as `stroke`, not + `currentColor`, so in forced-colours mode they may not follow the system colours. Not yet + tested. diff --git a/packages/ui/src/components/Spinner/accessibility.md b/packages/ui/src/components/Spinner/accessibility.md new file mode 100644 index 0000000..cff65a9 --- /dev/null +++ b/packages/ui/src/components/Spinner/accessibility.md @@ -0,0 +1,55 @@ +# Spinner: accessibility spec + +Pattern: no APG pattern. It uses the ARIA +[`progressbar` role](https://www.w3.org/TR/wai-aria-1.2/#progressbar) for indeterminate progress, +as React Native's `ActivityIndicator` does. Manual results: +[docs/assistive-technology-testing.md](../../../../../docs/assistive-technology-testing.md#spinner). + +## Role, name and states + +| Aspect | Web (React Native Web output) | iOS / Android (React Native props) | +| ------ | ------------------------------------------------------------ | --------------------------------------- | +| Role | `role="progressbar"` | `role="progressbar"` | +| Name | `aria-label` = `accessibilityLabel`, default "Loading" | `accessibilityLabel`, default "Loading" | +| Value | `aria-valuemin="0"`, `aria-valuemax="1"`, no `aria-valuenow` | none (indeterminate) | +| Inside | the animated SVG (see known issues) | `accessible`, so it is one element | + +The name has a default, so a spinner is never unnamed. Pass a more specific label ("Loading +results") when there is more than one on screen. + +## Keyboard + +| Key | Behaviour | +| --- | ----------------------------------- | +| - | None. A spinner is never focusable. | + +## Focus + +Never takes focus. Showing or hiding a spinner does not move focus. + +## Expected announcements + +| Screen reader | Must hear | +| ----------------- | --------------------------------------------------- | +| VoiceOver (macOS) | "Loading, progress indicator" (may add "busy") | +| VoiceOver (iOS) | "Loading" (the role word may not be spoken) | +| TalkBack | "Loading" (may add "progress bar" or "in progress") | +| NVDA | "Loading, progress bar" (no percentage) | + +The spinner does not announce itself when it appears: it is not a live region. The virtual +reader's transcripts (`e2e/__transcripts__/components-spinner--*.txt`) read "progressbar, Loading, max value 1, min value 0". + +## Known issues + +- **Appearing is silent.** A spinner that appears is only heard when the reading cursor reaches + it. A screen that loads should also announce the change, for example with + `AccessibilityInfo.announceForAccessibility` or a live region, or by marking the container + `aria-busy`. Button does the latter while loading. +- **"max value 1, min value 0".** React Native Web gives the indeterminate progressbar a min and + max, which some readers speak. An indeterminate progressbar should have neither. +- **The animation is read inside the progressbar.** The virtual reader reads a + "graphics-document" inside it. Real readers treat a progressbar's children as presentational, + so this is expected not to be heard; confirm in the manual pass (ADR 0010). +- **Reduced motion.** Spinner relies on the platform indicator and does not check the reduced + motion setting itself. Whether each platform slows or stops it is not yet checked; + `docs/accessibility.md` requires respecting the setting for components that animate. diff --git a/packages/ui/src/components/Stack/accessibility.md b/packages/ui/src/components/Stack/accessibility.md new file mode 100644 index 0000000..6d56a94 --- /dev/null +++ b/packages/ui/src/components/Stack/accessibility.md @@ -0,0 +1,46 @@ +# Stack: accessibility spec + +Pattern: no APG pattern. Stack is layout only: a `Box` with a flex direction and a theme gap. +Manual results: +[docs/assistive-technology-testing.md](../../../../../docs/assistive-technology-testing.md#stack). + +## Role, name and states + +| Aspect | Web (React Native Web output) | iOS / Android (React Native props) | +| ------ | ------------------------------------------------ | ---------------------------------- | +| Role | none: a plain `div` with `display: flex` | none: a plain `View` | +| Name | none | none | +| States | none | none | +| Props | any `Box` prop passes through (`role`, `aria-*`) | same | + +Stack must stay invisible to assistive technology. If its children form a list, the app passes +`role="list"` to the Stack and `role="listitem"` to each child. + +## Keyboard + +| Key | Behaviour | +| --- | --------------------------------------------------------------------- | +| Tab | Moves to focusable children in source order. The Stack is not a stop. | + +## Focus + +Never takes focus. Reading and Tab order follow the order of the children in the source, which +matches the visual order because Stack only lays out in `row` or `column`, never reversed (WCAG +1.3.2, 2.4.3). + +## Expected announcements + +| Screen reader | Must hear | +| ------------- | ---------------------------------------------------------- | +| All | The children only, in order. Nothing for the Stack itself. | + +The virtual reader's transcripts (`e2e/__transcripts__/components-stack--*.txt`) are empty, because the story's children are coloured boxes with no content. + +## Known issues + +- **A row does not reflow at 200% text.** `direction="row"` does not wrap; at large text sizes the + children can overflow on narrow screens (WCAG 1.4.10). Pass `flexWrap="wrap"` or switch to a + column at small widths. Not yet checked on devices. +- **Reversed directions are not offered on purpose.** `row-reverse` and `column-reverse` would + make the visual order differ from the reading order. If they are ever added, they need a known + issue here and a check in the keyboard suite. diff --git a/packages/ui/src/components/TextInput/accessibility.md b/packages/ui/src/components/TextInput/accessibility.md new file mode 100644 index 0000000..c76826c --- /dev/null +++ b/packages/ui/src/components/TextInput/accessibility.md @@ -0,0 +1,92 @@ +# TextInput: accessibility spec + +Pattern: there is no APG pattern for a plain text field; it follows the native `` and the +[APG guidance on labels and descriptions](https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/). +The password reveal follows the [APG Button](https://www.w3.org/WAI/ARIA/apg/patterns/button/) +pattern. Manual results: +[docs/assistive-technology-testing.md](../../../../../docs/assistive-technology-testing.md#textinput). + +## Role, name and states + +| Aspect | Web (React Native Web output) | iOS / Android (React Native props) | +| ----------- | --------------------------------------------------------------------- | -------------------------------------------------------- | +| Role | native `` (textbox; `type="password"` while hidden) | native text field | +| Name | `aria-labelledby` → the visible label; also `aria-label` from `label` | `accessibilityLabel` = `label` | +| Description | `aria-describedby` → the error, else the helper text | `accessibilityHint` = `errorText`, else `helperText` | +| Disabled | `aria-disabled="true"`, `readonly` (not editable), stays focusable | `editable={false}`, `aria-disabled` | +| Invalid | `aria-invalid="true"` while there is an error | the error is the hint; red border | +| Secure | `type="password"` until revealed | `secureTextEntry` until revealed | +| Error text | `role="alert"`, inside an always-mounted `aria-live="polite"` region | `role="alert"` inside `accessibilityLiveRegion="polite"` | + +The reveal button (only when `secure`): + +| Aspect | Web | iOS / Android | +| -------- | ---------------------------------------------- | ---------------------------------- | +| Role | `role="button"` | `role="button"` | +| Name | `aria-label` "Show password" / "Hide password" | `accessibilityLabel`, same strings | +| Disabled | follows the field's `disabled` | same | +| Icon | eye / eye-off, `aria-hidden` | hidden from the accessibility tree | + +`label` is required, so a field cannot be unnamed (WCAG 1.3.1, 3.3.2). + +## Keyboard + +| Key | Behaviour | +| ---------------------- | ------------------------------------------------------------------------ | +| Tab | Focuses the field, then the reveal button when `secure`. | +| Shift + Tab | Moves back through the same order. | +| Characters, editing | Native text editing. Nothing when disabled (read only). | +| Enter (field) | Native: `onSubmitEditing`. No default action on the web. | +| Enter / Space (reveal) | Toggles between showing and hiding the value; focus stays on the button. | + +`e2e/tests/keyboard.spec.ts` checks that the password can be revealed and hidden by keyboard. + +## Focus + +- The field shows focus by thickening its border from 1px to 2px and colouring it `primary` + (`fieldBorderColor`), on every focus, mouse or keyboard, as native inputs do. An invalid field + keeps its `danger` border while focused, so only the width changes. +- The reveal button uses the `Pressable` focus ring on keyboard focus only. +- Revealing the password does not move focus. A new error does not move focus; it is announced + through the live region instead. +- A disabled field is still reachable by Tab on the web (it is read only), so its value can be + read and copied. + +## Expected announcements + +| State | Must hear | +| ----------------------- | ----------------------------------------------------------------------- | +| Empty, with placeholder | "Email", text field (edit / edit text), the placeholder | +| With helper text | "Email", text field, then "We never share your email." | +| Disabled | "Email", text field, the value, dimmed / disabled / unavailable | +| With error | "Email", text field, the value, "Enter a valid email address.", invalid | +| Error appears | "Enter a valid email address." announced once, without moving focus | +| Password | "Password", secure text field; the value is not read aloud | +| Reveal button | "Show password, button"; after activating, "Hide password, button" | + +Per reader: VoiceOver says "text field" and "dimmed"; TalkBack says "edit box" and "disabled"; +NVDA says "edit" and "unavailable", and "invalid entry" for `aria-invalid`. The virtual reader's +web transcripts are `e2e/__transcripts__/components-textinput--*.txt`. + +## Known issues + +- **iOS and Android have no invalid state.** The error reaches them only as the hint and, on + Android, the live region. iOS ignores live regions, so an error that appears while the field is + focused is not announced on iOS; it needs `AccessibilityInfo.announceForAccessibility`. +- **The error is an alert inside a polite live region.** The region is always mounted, because + VoiceOver in Safari skips a live region that arrives with its text (found by the VoiceOver + suite). `role="alert"` implies `aria-live="assertive"`, so a reader may still announce it + assertively. Some readers announce an error twice (alert plus hint) when + it appears on a focused field. Needs manual testing. +- **The label is announced twice by some web readers.** The visible label is a separate text node + and also the field's name, so browse mode reads "Email" and then "Email, edit". This matches + native inputs with a `