# Accessibility

> Keyboard creation, moving and resizing of annotations, focus handling, ARIA structure, live announcements, forced colours, reduced motion, right-to-left layout and translation of the PDF viewer.

Everything in the viewer can be reached and operated from the keyboard, and its structure is exposed with standard ARIA patterns. The complete list of keys is on the [Keyboard shortcuts](https://docs.birchui.com/pdf/keyboard.md) page; this page explains how the pieces fit together.

## Moving through the viewer

The viewer has a small number of tab stops: the toolbar, the tool row of the open group, the sidebar and the document.

- **F6** moves focus from the document to the toolbar and back. Escape in a toolbar returns to the document.
- **Toolbars** use a roving tab stop: Tab enters and leaves the toolbar, the Left and Right arrows move between its controls, Home and End jump to the first and last. Inside the page box and other text fields the arrows move the caret until it reaches the end.
- **Menus** open on their first or checked item; Up, Down, Home and End move, Escape closes and returns focus to the button.
- **Sidebar tabs** move with the Left and Right arrows, Home and End.
- **Dialogs** (password, print, signature, properties, security, compare and the tool dialogs) are modal. Tab and Shift+Tab stay inside, Escape closes, and focus returns to where it was.
- **F4** shows and hides the sidebar; **Shift+?** opens the list of shortcuts.

Single-letter shortcuts are ignored while focus is in a text field, the sidebar, a toolbar, a menu, a dialog or the comment popover.

## Annotating with the keyboard

No annotation needs a pointer.

1. Choose a tool with its letter (for example T for a text box) or from the toolbar.
2. Press **Enter** in the document. The annotation is placed at the centre of the visible part of the current page, selected and focused. A text box opens for typing; a note opens its comment.
3. Move it with the **arrow keys** (1 px, **Shift** for 10 px). **Alt+arrow keys** resize it by moving its bottom-right corner, with Shift for 10 px.
4. **Enter** on a selected annotation edits its text or opens its comments. **Shift+F10** opens the context menu with copy, arrange, align, group, lock and delete. **Delete** removes it.
5. **Tab** and **Shift+Tab**, while an annotation has focus, go to the next and previous annotation on the page. Escape clears the selection, and pressed again returns to the Select tool.

What Enter places depends on the tool:

| Tool | Result |
| --- | --- |
| Highlight, underline, strikeout, squiggly, redact | Marks the current text selection. Without a selection nothing happens. |
| Insert text | Places a caret at the text cursor of the current selection, or at the centre of the page, and opens its comment. |
| Replace text | Strikes through the current text selection, places a caret at its end and opens its comment. Without a selection nothing happens. |
| Sticky note, text box, callout | Placed at the centre; the text box or callout opens for typing |
| Rectangle, ellipse, cloud, line, arrow, distance | A shape of a default size, to move and resize |
| Polygon, polyline, perimeter, area | A triangle of a default size |
| Draw | A short sample stroke |
| Stamp | The stamp chosen in the gallery |
| Signature | Opens the signature dialog if no signature is active, then places it |
| Form field (designer) | A field of the chosen type |

Text for a markup has to be selected first. With a keyboard that is done with the browser's caret browsing (F7 in Chrome, Edge and Firefox), because the text layer is ordinary selectable text.

The vertices of a polygon, polyline, perimeter, area, count, arc or angle can also be placed one by one: with the tool active and nothing selected, an arrow key shows a crosshair, the arrow keys move it (10 px, Shift for 50 px, Alt for 1 px), Enter places a vertex and a second Enter in the same place finishes the shape. A finished polygon, polyline, perimeter or area is edited the same way: Tab on the focused shape walks its vertices and edges, the arrow keys move a vertex, Delete removes it and Enter on an edge adds one. With the Eraser, Enter focuses the first drawing on the page, Tab walks its strokes and Delete erases the focused stroke. Each step is announced, and the focused handle or stroke is marked on the page. The keys are listed under [Keyboard](https://docs.birchui.com/pdf/keyboard.md#while-drawing).

Some things remain pointer-only: drawing freehand, the Draw tab of the signature dialog (Type and Upload work from the keyboard) and the marquee zoom. See [Limitations](https://docs.birchui.com/pdf/limitations.md#accessibility).

### Pages and bookmarks

- **Pages panel**: a multi-select list box. Arrow keys move, Shift+arrows extend the selection, Enter or Space goes to the page, Alt+ArrowUp and Alt+ArrowDown move the page, Delete deletes the selected pages.
- **Bookmarks panel**: a tree. Up and Down move, Right expands or enters, Left collapses or goes to the parent, Enter follows the bookmark.
- **Form designer**: a focused field box moves with the arrow keys, Delete removes it and Enter opens its properties.

## Structure

- The viewer is a labelled `region`; `ariaLabel` sets its name. The toolbar and the tool row are `toolbar`s; tool and group buttons expose `aria-pressed`, and buttons that open a menu expose `aria-haspopup` and `aria-expanded`.
- The sidebar is a `complementary` landmark with a `tablist`. The Pages panel is a `listbox` with `aria-multiselectable`, the Bookmarks panel a `tree`.
- The page area is a focusable `document`. Each page is a `region` named "Page 3 of 12", with the page label added when the document defines one.
- Page text is real text in a transparent layer over the canvas, in the order the package's text extractor returns it (logical order for right-to-left text), so screen readers can read it and it can be selected and copied.
- For a tagged PDF the structure tree is exposed on top of that text: headings with their level, paragraphs, lists and list items, tables with rows, header cells and cells, links, and figures and formulas with their alternative text. The structure elements own the text through `aria-owns`, so a screen reader meets the content in the order of the structure tree. Untagged documents are read in extraction order as before.
- Each annotation is a focusable `button` named by its type, author, text and reply count, for example "Highlight by Dana Whitfield: Confirm the registered address (1 reply)". One annotation per page is in the tab order.
- Form fields are native inputs with their tooltip or name as the label, `aria-required` and `aria-invalid`.
- Links in the document are real links and buttons with a label that names the target. A link annotation added in the viewer asks before it opens a web address and shows the full address.
- File attachment, sound and media annotations are named by their type and file name; **Download attachment** is in the annotation menu (`Shift` + `F10`).
- The content tools give every text run and image a focusable `button` named by its text or size.

## Announcements

Page changes, the result of a search ("Match 3 of 17"), tool changes, annotations added, moved, resized, copied, pasted and deleted, applied redactions, print progress and saving are announced in a polite live region. Errors, such as a tool that is not available or a document change that failed, go to an assertive one. The loading message of the document is a `status`, and the page area is `aria-busy` while a document loads.

## Colours, contrast and motion

- `theme: 'auto'` follows `prefers-color-scheme`; `'light'` and `'dark'` force one. The interface colours are chosen to meet WCAG 2.2 AA contrast in both themes.
- In **forced colours** mode (Windows high contrast) pressed buttons, selected tabs, the current list entry, selected thumbnails, the selection outline and resize handles use the system highlight colour, and menus, dialogs and pages get a visible border. Page content, search highlights and colour swatches keep their own colours.
- With **`prefers-reduced-motion`**, transitions, animations and smooth scrolling are turned off.
- Zoom goes up to 1600%, and Ctrl+wheel or pinch zooms without changing the size of the toolbar.

## Newer surfaces

- **Command palette.** A modal dialog with a combobox and a listbox: focus stays in the text box, `aria-activedescendant` follows the arrow keys, and unavailable commands are announced as disabled.
- **Document tabs.** A `tablist` whose tabs control the document area as a `tabpanel`. A tab with unsaved changes carries that in its accessible name. The close mark is a pointer target only; the keyboard equivalent is Delete on the focused tab, exposed through `aria-keyshortcuts`.
- **Layers panel.** A list of labelled checkboxes; focus stays on the checkbox after toggling.
- **Progressive loading.** The "Loading the document for editing…" line is a visible status region and is also announced.
- **Read aloud.** The highlighted line is decorative; the speech itself comes from the browser or from your `onText` callback.
- **Snapshot** needs a pointer to choose a region. **Copy the current page as an image** in the menu and the command palette is the keyboard alternative.

## Right to left

`rtl: true` mirrors the interface: the toolbar order, the side of the sidebar, arrow-key direction in toolbars and tabs, and the previous and next page buttons. Without the option, the viewer follows the `dir` attribute of its container or the nearest ancestor that has one. The page content itself is never mirrored.

The document tab strip, the Layers panel, the command palette and the other dialogs mirror as well; a browser test checks the positions of the sidebar, the toolbar buttons and the tab strip, the page order in spreads and horizontal scrolling, and runs the accessibility scan in a right-to-left page.

`pageDirection: 'rtl'` is separate: it is for documents that are read from right to left, and reverses the order of the pages in a spread and in horizontal scrolling.

## Translation

Every string of the interface is a key of `DEFAULT_LABELS`, including annotation type names (`typeHighlight`, `typeFreeText`, …), the descriptions in the shortcut list (`cmdZoomIn`, …) and the texts of signature fields. There are three ways to replace them, in order of precedence:

```ts
import { createPdfViewer } from '@birchui/pdf';

const viewer = createPdfViewer(document.querySelector<HTMLElement>('#vertrag')!, {
  locale: 'de',
  labels: {
    search: 'Suchen',
    matchOf: 'Treffer {current} von {total}',
    tools: { highlight: 'Markieren', note: 'Notiz' },
  },
  localeText: {
    'pdf.print': 'Drucken',
    'pdf.tools.freeText': 'Textfeld',
    'pdf.replies': { one: '{count} Antwort', other: '{count} Antworten' },
  },
});
```

- `labels` takes the keys of `DEFAULT_LABELS` directly, with tool names under `tools`.
- `localeText` uses the shared Birch UI translator with the same keys prefixed by `pdf.`, and `pdf.tools.` for tool names. Counted messages (`pdf.replies`, `pdf.redactionMarks`, `pdf.pagesSelected`, `pdf.commentCount`, `pdf.compareDifferences`, `pdf.searchResults`) accept plural forms. `setDefaultLocaleText` from `@birchui/core` sets it once for every component.
- `locale` (default `'en'`) selects the plural rules and the format of dates in stamps, signatures and the properties dialog.

Placeholders in braces, such as `{current}`, must be kept. `viewer.update({ labels, localeText, locale })` rebuilds the toolbar and sidebar in the new language.

### Locale packs

The package ships a complete set of labels for the seven languages of `@birchui/core`: `pdfLocaleEn`, `pdfLocaleDe`, `pdfLocaleFr`, `pdfLocaleEs`, `pdfLocalePt` (Brazilian Portuguese), `pdfLocaleJa` and `pdfLocaleZh` (Simplified Chinese). A pack is a `PdfViewerLabels` object, so it goes into `labels`; set `locale` as well for the plural rules and the date formats.

```ts
import { createPdfViewer, pdfLocaleDe } from '@birchui/pdf';

const viewer = createPdfViewer(document.querySelector<HTMLElement>('#vertrag')!, {
  locale: 'de',
  labels: pdfLocaleDe,
});
```

Each pack is a module of its own and nothing else in the package imports it, so a bundler keeps only the packs you import. To change a few terms, spread the pack and replace the keys; to switch language at run time, pass another pack to `update`:

```ts
import { pdfLocaleFr, pdfLocaleJa, type PdfViewerOptions } from '@birchui/pdf';

const french: PdfViewerOptions['labels'] = {
  ...pdfLocaleFr,
  annotations: 'Remarques',
  tools: { ...pdfLocaleFr.tools, note: 'Pense-bête' },
};

viewer.update({ locale: 'fr', labels: french });
viewer.update({ locale: 'ja', labels: pdfLocaleJa });
```

A string in `labels` wins over the `localeText` entry for the same key. The counted messages are the exception: a pack holds a singular and a plural label for each (`repliesOne`, `repliesOther`), and a plural entry in `localeText`, such as `pdf.replies`, replaces both. Use that for languages with more than two plural forms. `pdfLocaleEn` is `DEFAULT_LABELS` under the name the other packs follow. A test compares every pack with the English labels: same keys, no empty text and the same placeholders in every message.

## How it is tested

The end-to-end suite runs axe-core with the WCAG 2.0, 2.1 and 2.2 level A and AA rule sets against the viewer in the light and the dark theme, with the tool row, the shortcut dialog and the redaction panel open, and expects no serious or critical finding. Two things are outside that scan:

- **The content of the PDF.** The reading order, alternative texts and language of a document come from the document. The viewer passes the tag structure on; it cannot repair a document that has none or a wrong one.
- **The target size of form fields.** The form field layer is part of the scan, with one rule left out at the default zoom: the size of a form control is the size of the widget rectangle in the PDF, so small or tightly stacked fields can be below the 24 px target size until the user zooms in. At 150 % the sample form passes that rule too.

Further tests cover a tagged document (roles, heading levels, alternative text and reading order), a 390 px wide viewer (no sideways scrolling, overflowed commands reachable from the menu) and a run in which every label is replaced, which fails when a built-in English text is left in the interface.

An automated scan finds a part of the possible problems. Test with the screen readers your users have.

## Checking a document

The sections above are about the viewer. The document it shows can be checked too: **Accessibility check** in the menu (command `accessibilityCheck`) lists what assistive technology will miss, and lets you set the document language and the alternate text of figures in place. From code:

```ts
const report = viewer.checkAccessibility();
for (const issue of report.issues) console.info(issue.severity, issue.code, issue.pageIndex, issue.message);
await viewer.setLanguage('en-GB');
for (const figure of viewer.getFigures())
  if (!figure.alternateText) await viewer.setAlternateText(figure.id, 'Bar chart of shipments by lane');
```

The headless document has the same four methods. `setAlternateText` and `setLanguage` are undo steps and are written by an incremental save. The title is set with `setMetadata({ title })`.

| Code | Severity | Reported when |
| --- | --- | --- |
| `no-title` | error | Neither the document information nor the XMP metadata has a title |
| `title-not-shown` | warning | There is a title but `DisplayDocTitle` is not set, so readers show the file name |
| `no-language` | error | The catalog has no `Lang` |
| `not-tagged` | error | The document is not marked as tagged or has no structure tree |
| `figure-without-alt` | error | A `Figure` or `Formula` element (after the role map) has neither `Alt` nor `ActualText`; `figureId` names it |
| `untagged-content` | warning | Text of a tagged page lies outside marked content with an identifier and is not an artifact |
| `reading-order` | warning | On a page, at least a fifth of the steps of the tag order jump back up within the same column |
| `page-without-text` | error | A page has an image and no text; run [text recognition](https://docs.birchui.com/pdf/ocr.md) |
| `field-without-tooltip` | warning | A form field other than a signature has no tooltip (`TU`) |
| `tab-order` | warning | A tagged page with annotations does not use structure order for tabbing |
| `no-bookmarks` | warning | The document has more than 20 pages and no outline |

`passes` is `true` when no issue has severity `error`. This is a pre-flight check of eleven things, not a statement of conformance with PDF/UA or WCAG: it does not check colour contrast, table header relations, heading nesting, list structure, link text, the quality of alternate text or whether the tags describe the content correctly, and the reading-order test is a heuristic that looks at vertical jumps only. The package does not create tags for an untagged document and does not let you reorder tags.
