11The ` a11y ` package provides a number of tools to improve accessibility, described below.
22
3- ## ListKeyManager
3+ ### ListKeyManager
4+
45` ListKeyManager ` manages the active option in a list of items based on keyboard interaction.
56Intended to be used with components that correspond to a ` role="menu" ` or ` role="listbox" ` pattern.
67
7- ### Basic usage
8+ #### Basic usage
9+
810Any component that uses a ` ListKeyManager ` will generally do three things:
911* Create a ` @ViewChildren ` query for the options being managed.
1012* Initialize the ` ListKeyManager ` , passing in the options.
@@ -18,16 +20,19 @@ interface ListKeyManagerOption {
1820}
1921```
2022
21- ### Wrapping
23+ #### Wrapping
24+
2225Navigation through options can be made to wrap via the ` withWrap ` method
2326``` ts
2427this .keyManager = new FocusKeyManager (... ).withWrap ();
2528```
2629
27- ### Types of key managers
30+ #### Types of key managers
31+
2832There are two varieties of ` ListKeyManager ` , ` FocusKeyManager ` and ` ActiveDescendantKeyManager ` .
2933
30- #### FocusKeyManager
34+ ##### FocusKeyManager
35+
3136Used when options will directly receive browser focus. Each item managed must implement the
3237` FocusableOption ` interface:
3338``` ts
@@ -36,7 +41,8 @@ interface FocusableOption extends ListKeyManagerOption {
3641}
3742```
3843
39- #### ActiveDescendantKeyManager
44+ ##### ActiveDescendantKeyManager
45+
4046Used when options will be marked as active via ` aria-activedescendant ` .
4147Each item managed must implement the
4248` Highlightable ` interface:
@@ -50,15 +56,17 @@ interface Highlightable extends ListKeyManagerOption {
5056Each item must also have an ID bound to the listbox's or menu's ` aria-activedescendant ` .
5157
5258
53- ## FocusTrap
59+ ### FocusTrap
60+
5461The ` cdkTrapFocus ` directive traps <kbd >Tab</kbd > key focus within an element. This is intended to
5562be used to create accessible experience for components like
5663[ modal dialogs] ( https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal ) , where focus must be
5764constrained.
5865
5966This directive is declared in ` A11yModule ` .
6067
61- ### Example
68+ #### Example
69+
6270``` html
6371<div class =" my-inner-dialog-content" cdkTrapFocus >
6472 <!-- Tab and Shift + Tab will not leave this element. -->
@@ -68,7 +76,8 @@ This directive is declared in `A11yModule`.
6876This directive will not prevent focus from moving out of the trapped region due to mouse
6977interaction.
7078
71- ### Regions
79+ #### Regions
80+
7281Regions can be declared explicitly with an initial focus element by using
7382the ` cdkFocusRegionStart ` , ` cdkFocusRegionEnd ` and ` cdkFocusInitial ` DOM attributes.
7483` cdkFocusInitial ` specifies the element that will receive focus upon initialization of the region.
@@ -88,18 +97,21 @@ For example:
8897will happen unless you've enabled the ` cdkTrapFocusAutoCapture ` option as well. This is due to
8998` CdkTrapFocus ` not capturing focus on initialization by default.
9099
91- ## InteractivityChecker
100+ ### InteractivityChecker
101+
92102` InteractivityChecker ` is used to check the interactivity of an element, capturing disabled,
93103visible, tabbable, and focusable states for accessibility purposes. See the API docs for more
94104details.
95105
96106
97- ## LiveAnnouncer
107+ ### LiveAnnouncer
108+
98109` LiveAnnouncer ` is used to announce messages for screen-reader users using an ` aria-live ` region.
99110See [ the W3C's WAI-ARIA] ( https://www.w3.org/WAI/PF/aria-1.1/states_and_properties#aria-live )
100111for more information on aria-live regions.
101112
102- ### Example
113+ #### Example
114+
103115``` ts
104116@Component ({... })
105117export class MyComponent {
@@ -110,10 +122,11 @@ export class MyComponent {
110122}
111123```
112124
113- ## FocusMonitor
125+ ### FocusMonitor
126+
114127The ` FocusMonitor ` is an injectable service that can be used to listen for changes in the focus
115128state of an element. It's more powerful than just listening for ` focus ` or ` blur ` events because it
116- tells you how the element was focused (via mouse, keyboard, touch, or programmatically). It also
129+ tells you how the element was focused (via the mouse, keyboard, touch, or programmatically). It also
117130allows listening for focus on descendant elements if desired.
118131
119132To listen for focus changes on an element, use the ` monitor ` method which takes an element to
@@ -133,7 +146,7 @@ to the element when focused. It will add `.cdk-focused` if the element is focuse
133146add ` .cdk-${origin}-focused ` (with ` ${origin} ` being ` mouse ` , ` keyboard ` , ` touch ` , or ` program ` ) to
134147indicate how the element was focused.
135148
136- Note: currently the ` FocusMonitor ` emits on the observable _ outside_ of the Angular zone. Therefore
149+ Note: currently the ` FocusMonitor ` emits on the observable _ outside_ of the Angular zone. Therefore,
137150if you ` markForCheck ` in the subscription you must put yourself back in the Angular zone.
138151
139152``` ts
@@ -148,12 +161,13 @@ Any element that is monitored by calling `monitor` should eventually be unmonito
148161It is possible to falsify the ` FocusOrigin ` when setting the focus programmatically by using the
149162` focusVia ` method of ` FocusMonitor ` . This method accepts an element to focus and the ` FocusOrigin `
150163to use. If the element being focused is currently being monitored by the ` FocusMonitor ` it will
151- report the ` FocusOrigin ` that was passed in. If the element is not currently being monitored it will
152- just be focused like normal.
164+ report the ` FocusOrigin ` that was passed in. If the element is not currently being monitored, it
165+ will just be focused like normal.
153166
154167<!-- example(focus-monitor-focus-via) -->
155168
156- ### cdkMonitorElementFocus and cdkMonitorSubtreeFocus
169+ #### cdkMonitorElementFocus and cdkMonitorSubtreeFocus
170+
157171For convenience, the CDK also provides two directives that allow for easily monitoring an element.
158172` cdkMonitorElementFocus ` is the equivalent of calling ` monitor ` on the host element with
159173` checkChildren ` set to ` false ` . ` cdkMonitorSubtreeFocus ` is the equivalent of calling ` monitor ` on
@@ -162,7 +176,8 @@ the host element with `checkChildren` set to `true`. Each of these directives ha
162176
163177<!-- example(focus-monitor-directives) -->
164178
165- ## Styling utilities
179+ ### Styling utilities
180+
166181The CDK ` a11y ` package comes with a set of CSS styles that can be used when building accessible
167182components. To take advantage of them, you have to include the styles in your global stylesheet.
168183If you're using Material together with the CDK, these styles have been included for you already.
@@ -173,9 +188,10 @@ If you're using Material together with the CDK, these styles have been included
173188@include cdk-a11y ();
174189```
175190
176- ### Hiding elements, while keeping them available for screen readers
191+ #### Hiding elements in an accessible way
192+
177193By default, screen readers and other assistive technology will skip elements that have
178- ` display: none ` , ` visibility: hidden ` etc. In some cases you may need to visually hide an element,
194+ ` display: none ` , ` visibility: hidden ` , etc. In some cases you may need to visually hide an element,
179195while keeping it available for assistive technology. You can do so using the ` cdk-visually-hidden `
180196class:
181197
@@ -185,7 +201,8 @@ class:
185201</div >
186202```
187203
188- ### Targeting high contrast users
204+ #### Targeting high contrast users
205+
189206The ` a11y ` package offers a mixin that allows you to target users that have the Windows high
190207contrast mode turned on. To target high contrast users, you can wrap your styles with the
191208` cdk-high-contrast ` mixin. The mixin works by targeting a CSS class which is added to the ` body `
0 commit comments