Accessibility
LynxAccessibility speaks to screen readers from code, the accessibility-* attributes describe elements to them, LynxAccessibilityTraits adds traits such as selected from a binding, LynxAccessibilitySettings reads the user's display settings, and provideAccessibilityWords() gives the words ARIA states are said in. import { LynxAccessibility, LynxAccessibilitySettings, LynxAccessibilityTraits, provideAccessibilityWords } from '@blotch/angular-lynx';
Usage
The screen reader is VoiceOver on iOS and TalkBack on Android.
API
LynxAccessibility
Imperative screen reader control, for changes that the attributes below can't express.
Both methods work from event handlers.
LynxAccessibility.announce()
Makes the screen reader speak content without moving focus. Use it for results that don't move focus, such as "Saved" or a finished upload.
- Resolves once Lynx accepts the announcement.
- Rejects when Lynx's announce API isn't available, such as in the web preview.
- From an event handler, the call runs on the background thread, the only one with Lynx's announce API. AngularLynx sends it there for you.
LynxAccessibility.requestFocus()
Moves the screen reader's focus to the element that matches selector. Give that element accessibility-element="true".
selector: use an ID selector such as'#confirmation', which matches the element'sid. Other selectors aren't reliable.- Rejects when no element matches, or with the Lynx error code when the element can't take focus.
LynxAccessibilityTraits
Adds traits to the element's own accessibility-traits while a binding says so. Use it for state that changes, such as selected on the chosen one of several options, or disabled. It's part of LYNX_ELEMENTS, so any component that imports LYNX_ELEMENTS can bind it.
- A trait that's
trueis added after the element's own:buttonreadsbutton,selectedon iOS. - A trait that turns
false, or that the map leaves out, is taken away. Only the traits the binding added are: the element's ownaccessibility-traitsstay. - Android keeps the element's own trait. It reads a single trait and has no selected or disabled trait, so a list would read as no trait at all. Writing
accessibility-traits="button,selected"yourself stops the element being a button there; this doesn't. - On a component's own host, which its template can't bind, call
setAccessibilityTrait(trait, on)on the host'sBaseLynxElementinstead. It merges the trait the same way.
LynxAccessibilitySettings
The user's display settings, as signals that update when the user changes one.
reduceMotion(): the user asked for less motion. Replace slides and bounces with a fade or an instant change.reduceTransparency(): the user asked for less transparency. Draw blurred and translucent surfaces opaque.increaseContrast(): the user asked for more contrast. Strengthen edges and use full-strength text colors.textScale(): how much larger than the system's default the user's text is. It's1at the default,1.5for text half as large again, and below1at iOS's smaller sizes. The app's text already follows it (see Follow the phone's text size), so read it only to change a layout that can't simply grow.
Lynx has no API for these, so they come from the host app, as the theme does, in the reduceMotion, reduceTransparency, increaseContrast and textScale global props. Each switch is off unless it's true, and textScale is 1 unless it's a positive number.
iOS 27's Liquid Glass setting (clear or tinted glass) has no public API, so it isn't here. iOS's own glass follows it.
ACCESSIBILITY_WORDS
The words screen readers say for the ARIA attributes that Lynx has no state or trait for, which AngularLynx gives as text: an accessibility-value such as "Checked", and on Android an accessibility-role-description such as "Tab". Dolan's checkbox, switch and slider say theirs in the same words. English unless the app provides its own. The renderer reads them once, as the app starts.
provideAccessibilityWords()
Provides ACCESSIBILITY_WORDS: the words given replace the English ones, and the rest stay English. A function runs in an injection context as the app starts, so $localize in it sees the translations main.ts loaded. See Say states in your app's language.
Attributes
Every Lynx element accepts these attributes. Set them as static attributes, or bind them with [accessibility-label]="label()", which type-checks.
Some are read on one platform only:
accessibility-traits takes one of 'text', 'image', 'button', 'link', 'header', 'search', 'selected', 'playable', 'keyboard', 'summary', 'disabled', 'updating', 'adjustable', 'tabbar' or 'none'.
- iOS also takes several, separated by commas with no spaces, such as
'button,selected'. - Android reads a single
'none','image'or'button', and ignores the rest. - HarmonyOS, like Android, reads a single trait:
'button','image'or'text'. - An active
routerLinkActiveelement getsselectedadded to its own traits. To add one from your own state, useLynxAccessibilityTraits.
Write the plural: Lynx ignores accessibility-trait. ng update renames it in apps written before 22.2.3, when LYNX_ELEMENTS declared the singular.
ARIA attributes
On iOS and Android, aria-label, aria-labelledby, aria-hidden, aria-modal, aria-valuetext, aria-checked, aria-pressed, aria-expanded, aria-valuenow (with aria-valuemin and aria-valuemax), aria-selected, aria-disabled and role give the attributes above, the states in the words of ACCESSIBILITY_WORDS. The rest of ARIA does nothing. Use ARIA attributes has the table. An attribute above that you set yourself wins over the one ARIA gives.
Types
AccessibilityTrait
One trait of accessibility-traits.
AccessibilityTraitStates
What [lynxAccessibilityTraits] takes: each trait to add, by name, with whether to add it now.
AccessibilityWords
The words of ACCESSIBILITY_WORDS, with their English.
Related
- Accessibility: labeling, grouping and focus traps.
- Elements: the other attributes every element accepts.
- Lynx accessibility docs
