Accessibility
Screen readers read your app aloud and let people move through it by touch: VoiceOver on iPhone and TalkBack on Android. Lynx elements take attributes that tell the screen reader what each element is and what to say.
id, a11y-id and name
Three attributes name an element, and they're often confused:
Use id unless you have a reason not to.
Label an element
<text>and<image>are read by default. A<text>reads its own text, so most text needs nothing extra.[accessibility-element]="true"makes an element one stop for the screen reader. Use it on a<view>that acts as a button or groups related content.- Bind true/false attributes with brackets. A plain
accessibility-element="true"passes the string"true", which Angular's strict template checks reject. accessibility-labelis what gets read. Give one to anything without readable text, such as an icon button.accessibility-traitssays what kind of thing it is, such asbutton,image,linkorheader. Note the plural: Lynx ignoresaccessibility-trait.
Set the reading order
- Screen readers go top to bottom, then left to right, by default.
accessibility-elementslists childids, separated by commas, in the order to read them. The example reads the title before the price.- Children not in the list can't be focused once a parent sets it.
accessibility-elements-a11ydoes the same witha11y-ids.
Hide decoration
[accessibility-elements-hidden]="true" hides an element and everything inside it from the screen reader.
Keep focus inside a dialog
With [accessibility-exclusive-focus]="true", the screen reader moves only between the elements inside it. People can't swipe out of the dialog to the page behind. See Dialogs and overlays.
Announce changes and move focus from code
Some changes don't move the screen reader, such as a cart count going up. Tell people about them with LynxAccessibility:
announce(text)makes the screen reader speak, without moving focus.requestFocus('#id')moves the screen reader to the element with thatid, such asrequestFocus('#total').- Both return a Promise that rejects where Lynx can't do it, such as in the web preview. The
catchkeeps that quiet.
The signatures are in the API reference.
Test with a screen reader
On an iPhone:
- Open Settings → Accessibility → VoiceOver and turn it on.
- Swipe right or left to move between elements. Double-tap anywhere to tap the selected one.
- To toggle it quickly, set Settings → Accessibility → Accessibility Shortcut to VoiceOver, then triple-click the side button.
VoiceOver doesn't run in the iOS Simulator, the virtual iPhone on your Mac. Instead, open Accessibility Inspector from Xcode's Xcode → Open Developer Tool menu and point it at the Simulator. It shows the label and traits of each element you hover.
On Android:
- Open Settings → Accessibility → TalkBack and turn it on. On some phones, it's under Installed apps or Downloaded apps in that menu.
- Swipe right or left to move between elements. Double-tap to tap the selected one.
TalkBack also runs in the Android emulator, the virtual Android phone on your computer. Drag with the mouse to swipe. If its Settings has no TalkBack, install Android Accessibility Suite from the Play Store, which needs an emulator image with Google Play.
You can test either way in Lynx Explorer or in your own app. AngularLynx turns on Lynx's accessibility support in every build, so there's nothing to enable.
Common attributes
The full list, with platform support, is in the accessibility API reference.
