Skip to main content

Accessibility

The mounted web editor draws the document on a canvas, which assistive technology can't read. So it also puts the document in the page in two forms screen readers can use, and says what changes as the user works. This guide says what the editor does, what your application does, and how each WCAG 2.1 A and AA success criterion is covered.

Three words​

  • The reading structure is the document as data: editor.accessibility.tree() returns it, and the AccessibleNode types describe it. Every node has an id that stays the same while the thing it names exists.
  • The mirror is that structure as ARIA elements in the editor's container, out of sight but not hidden from assistive technology. Screen reader users read and navigate it in browse mode: by heading, list, table, link, graphic and region.
  • The editing element is the element that has the keyboard focus while the editor does. It holds the text around the caret (the caret's paragraph and its neighbours, in their laid-out lines) and the selection, so the screen reader reads characters, words, lines and paragraphs as the caret moves, and echoes typing and deleting.

What a screen reader user gets​

  • Tab into the editor: the screen reader says its name (the mount's label, default "Document"), that it is an editable multi-line text, and how to leave it. F6 (Shift+F6 for the stop before), as Word's F6 goes to the next pane, or Escape, then Tab (or Shift+Tab), moves the focus out; Tab alone stays the editor's (a tab, an indent, the next cell). Screen readers keep the first Escape for themselves (NVDA's turns focus mode off), so with one, F6 is the way out, or Escape twice, then Tab.
  • In browse mode, the mirror has headings with levels, lists with their numbers and positions, tables with column headers, spans and nesting, links, pictures named by their alternative text (decorative ones are left out), text boxes after the paragraph they are anchored in, and, after the body, regions for headers and footers, footnotes, endnotes and comments. Commented text points at its comment, insertions and deletions are marked with their author, misspelled words are marked, and text in another language says so. Enter on a node puts the caret there.
  • While editing, the editor announces, in a polite live region: entering, leaving and moving through tables; entering and leaving lists; another page; entering a header, footer, footnote, endnote or text box; entering read-only content and an edit refused there; insertions and deletions with their author; comments with their author and text; a misspelled word; formatting turned on or off; select all; and what undo, redo, cut, copy and paste did.
  • Shift+F1 says the formatting at the caret: paragraph style, font and size, emphasis, colour and highlight.

The API​

import { Editor } from '@twip/web';

const container = document.querySelector<HTMLElement>('#editor')!;

// The name screen readers say when the editor gets the focus. Put a visible label near the container too.
const editor = await Editor.mount(container, { label: 'Letter body' });

// What the editor says to screen readers, for a log or your own live region.
editor.on('announcement', ({ text, kind }) => console.log(`${kind}: ${text}`));

// Only some kinds: the others are neither spoken nor emitted.
await editor.accessibility.setAnnouncements(['table', 'list', 'review', 'comment', 'spelling', 'mode', 'readOnly', 'command', 'selection']);

// A navigation pane of your own: go to the first heading, as a screen reader's Enter on it does.
const tree = await editor.accessibility.tree();
const heading = tree.children.find((n) => n.role === 'heading');
if (heading) await editor.accessibility.go(heading.id);

// Shift+F1 says the formatting at the caret; a toolbar button can do the same.
await editor.commands.describeFormatting();
  • MountOptions.label: the editor's accessible name.
  • accessibility.tree(): the reading structure; accessibility.go(id): the caret to a node's start (a note reference goes to its note, a comment to its commented text).
  • accessibility.setAnnouncements(kinds): the kinds the editor announces (table, list, page, review, comment, spelling, formatting, mode, readOnly, command, selection); the others are neither spoken nor emitted. Default: all.
  • The announcement event: { text, kind } for each announcement. When one change says several things, they are one announcement and kind is the first one's.
  • commands.describeFormatting(): what Shift+F1 does.

The .NET SDK has the same tree, announcements and methods (Accessibility.GetTreeAsync, GoAsync, SetAnnouncementsAsync, Commands.DescribeFormattingAsync, the AccessibilityAnnouncement event).

What the editor adds to its container​

container
└── div[data-twip="editor"]
├── canvas[data-twip="canvas"] aria-hidden="true"
└── div[data-twip="content"] > div[data-twip="layer"]
├── div[data-twip="input"] the editing element: contenteditable, role="textbox", aria-multiline,
│ aria-label, aria-description (the way out), lang, aria-readonly
├── div[data-twip="a11y"] the mirror: role="document" with the structure inside
└── div[data-twip="live"] role="status", aria-live="polite"

Mirror elements carry data-twip-id (the node's id). The editor creates and removes all of it; don't change it.

What your application does​

  • Make your own chrome accessible: toolbars, menus, dialogs, comment cards, the navigation pane. The editor's services give you their models; drawing them, and their keyboard and screen reader behaviour, is yours.
  • Give the editor a visible label near it, and pass the same words as label.
  • Don't hide the editor's container from assistive technology (aria-hidden, inert), and don't trap the focus around it.
  • Give the page a title and a language, and a way to skip to the editor.

WCAG 2.1 A and AA​

Status: Twip (the editor meets it), later (Twip's, not met yet), application (your page and UI), not applicable (the editor has no such content). Twip's are checked by engine tests (the reading structure, caret window and announcements), browser tests (the DOM above) and a suite outside this repository that drives NVDA and checks axe-core's rules.

CriterionLevelStatusHow
1.1.1 Non-text ContentATwipPictures and shapes are named by their alternative text; decorative ones and the canvas are hidden. The text is the document author's.
1.2.1 Audio-only and Video-only (Prerecorded)Anot applicableNo time-based media.
1.2.2 Captions (Prerecorded)Anot applicableNo time-based media.
1.2.3 Audio Description or Media Alternative (Prerecorded)Anot applicableNo time-based media.
1.2.4 Captions (Live)AAnot applicableNo time-based media.
1.2.5 Audio Description (Prerecorded)AAnot applicableNo time-based media.
1.3.1 Info and RelationshipsATwipHeadings, lists, tables with header cells, links, notes, comments and regions in the mirror.
1.3.2 Meaningful SequenceATwipThe body in order, floating content at its anchor, the regions after the body.
1.3.3 Sensory CharacteristicsAapplicationThe editor's own instructions name keys, not shapes or places.
1.3.4 OrientationAAapplicationThe editor works in either orientation.
1.3.5 Identify Input PurposeAAapplicationDocument text has no input purpose; your forms do.
1.4.1 Use of ColorATwipInsertions, deletions, comments and misspellings are marked and announced, not only coloured.
1.4.2 Audio ControlAnot applicableNo audio.
1.4.3 Contrast (Minimum)AAlaterThe colours the editor draws (selection, marks, caret) aren't checked yet; forced-colours mode is followed. The document's colours are its author's.
1.4.4 Resize TextAAlaterZoom enlarges the document; the editor doesn't follow the browser's text size setting yet.
1.4.5 Images of TextAAlaterThe canvas draws text as pixels; the editing element and the mirror carry it as text, but it can't be restyled.
1.4.10 ReflowAAlaterPages keep their width; zoom to page width is available.
1.4.11 Non-text ContrastAAlaterThe caret, selection and handles aren't checked yet.
1.4.12 Text SpacingAAlaterCanvas text doesn't take user style sheets.
1.4.13 Content on Hover or FocusAAapplicationThe editor emits tooltip events; your application draws the tooltip.
2.1.1 KeyboardATwipEvery editing operation has a key or a command; your chrome is yours.
2.1.2 No Keyboard TrapATwipF6, or Escape then Tab, leaves the editor; the editing element's description says so.
2.1.4 Character Key ShortcutsATwipThe editor's shortcuts use a modifier or a function key; shortcuts you register are yours.
2.2.1 Timing AdjustableAnot applicableThe editor has no time limits.
2.2.2 Pause, Stop, HideATwipThe caret's blink stops under reduced motion, and caretBlinkStopAfter stops it after a while.
2.3.1 Three Flashes or Below ThresholdATwipThe caret blinks at under two flashes a second.
2.4.1 Bypass BlocksAapplicationA skip link to the editor is your page's.
2.4.2 Page TitledAapplicationYour page's title.
2.4.3 Focus OrderATwipThe editor is one tab stop; your page's order is yours.
2.4.4 Link Purpose (In Context)ATwipLinks are links with their text; the text is the author's.
2.4.5 Multiple WaysAAapplicationYour application's navigation.
2.4.6 Headings and LabelsAATwipThe editor's label (label) and the document's headings.
2.4.7 Focus VisibleAAlaterThe caret shows where the focus is; the editor draws no focus outline around itself yet.
2.5.1 Pointer GesturesAlaterDragging objects and borders has commands, but not every drag has a key yet.
2.5.2 Pointer CancellationAlaterNot checked yet.
2.5.3 Label in NameAapplicationKeep label the same as the visible label.
2.5.4 Motion ActuationAnot applicableNo motion input.
3.1.1 Language of PageATwipThe mirror has the document's language; the page's is yours.
3.1.2 Language of PartsAATwipText in another language is marked with it, in the mirror and the editing element.
3.2.1 On FocusATwipFocusing the editor changes nothing.
3.2.2 On InputATwipTyping changes only the document.
3.2.3 Consistent NavigationAAapplicationYour application's navigation.
3.2.4 Consistent IdentificationAAapplicationYour application's controls.
3.3.1 Error IdentificationATwipMisspellings are marked and announced; an edit refused in read-only content says why.
3.3.2 Labels or InstructionsATwipThe editor's label and the way out; your forms are yours.
3.3.3 Error SuggestionAATwipThe spelling service gives suggestions; your application shows them.
3.3.4 Error Prevention (Legal, Financial, Data)AAapplicationUndo is always there; confirming a submission is yours.
4.1.1 ParsingATwipThe editor builds its DOM through DOM calls.
4.1.2 Name, Role, ValueATwipThe editing element is a named multi-line text box with its text and selection; mirror elements have their roles and names.
4.1.3 Status MessagesAATwipAnnouncements go to a polite live region and never move the focus.