Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
Expand Down
13 changes: 11 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Name>`. It writes the component, test, story and
index in `packages/ui/src/components/<Name>/` and exports it. Then build it from primitives.
- **A new component:** `yarn new:component <Name>`. It writes the component, test, story,
index and accessibility spec stub in `packages/ui/src/components/<Name>/` 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
Expand All @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion docs/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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).
Expand All @@ -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`).
Expand Down
139 changes: 139 additions & 0 deletions docs/assistive-technology-testing.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 6 additions & 4 deletions docs/engineering-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<Name>/` holds `<Name>.tsx`, `<Name>.test.tsx`, `<Name>.stories.tsx`
and `index.ts`, the stories are titled `Components/<Name>`, 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/<Name>/` holds `<Name>.tsx`, `<Name>.test.tsx`, `<Name>.stories.tsx`,
`index.ts` and an `accessibility.md` spec with every section, the stories are titled
`Components/<Name>`, `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.
Expand Down
38 changes: 34 additions & 4 deletions packages/ui/src/__contracts__/component-structure.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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}';`);
});
Expand Down
Loading
Loading