Skip to content

Commit 4aa48a1

Browse files
authored
docs(cdk/a11y): fix overview table of contents (angular#22136)
- while the guides were updated to support a wider set of headers, component docs are still limited to h3 and h4 in the TOC - this fixes a regression to these docs introduced in v6 Fixes angular#22133
1 parent fef9179 commit 4aa48a1

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

src/cdk/a11y/a11y.md

+39-22
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
The `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.
56
Intended to be used with components that correspond to a `role="menu"` or `role="listbox"` pattern.
67

7-
### Basic usage
8+
#### Basic usage
9+
810
Any 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+
2225
Navigation through options can be made to wrap via the `withWrap` method
2326
```ts
2427
this.keyManager = new FocusKeyManager(...).withWrap();
2528
```
2629

27-
### Types of key managers
30+
#### Types of key managers
31+
2832
There are two varieties of `ListKeyManager`, `FocusKeyManager` and `ActiveDescendantKeyManager`.
2933

30-
#### FocusKeyManager
34+
##### FocusKeyManager
35+
3136
Used 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+
4046
Used when options will be marked as active via `aria-activedescendant`.
4147
Each item managed must implement the
4248
`Highlightable` interface:
@@ -50,15 +56,17 @@ interface Highlightable extends ListKeyManagerOption {
5056
Each item must also have an ID bound to the listbox's or menu's `aria-activedescendant`.
5157

5258

53-
## FocusTrap
59+
### FocusTrap
60+
5461
The `cdkTrapFocus` directive traps <kbd>Tab</kbd> key focus within an element. This is intended to
5562
be 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
5764
constrained.
5865

5966
This 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`.
6876
This directive will not prevent focus from moving out of the trapped region due to mouse
6977
interaction.
7078

71-
### Regions
79+
#### Regions
80+
7281
Regions can be declared explicitly with an initial focus element by using
7382
the `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:
8897
will 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,
93103
visible, tabbable, and focusable states for accessibility purposes. See the API docs for more
94104
details.
95105

96106

97-
## LiveAnnouncer
107+
### LiveAnnouncer
108+
98109
`LiveAnnouncer` is used to announce messages for screen-reader users using an `aria-live` region.
99110
See [the W3C's WAI-ARIA](https://www.w3.org/WAI/PF/aria-1.1/states_and_properties#aria-live)
100111
for more information on aria-live regions.
101112

102-
### Example
113+
#### Example
114+
103115
```ts
104116
@Component({...})
105117
export class MyComponent {
@@ -110,10 +122,11 @@ export class MyComponent {
110122
}
111123
```
112124

113-
## FocusMonitor
125+
### FocusMonitor
126+
114127
The `FocusMonitor` is an injectable service that can be used to listen for changes in the focus
115128
state 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
117130
allows listening for focus on descendant elements if desired.
118131

119132
To 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
133146
add `.cdk-${origin}-focused` (with `${origin}` being `mouse`, `keyboard`, `touch`, or `program`) to
134147
indicate 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,
137150
if 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
148161
It 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`
150163
to 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+
157171
For 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+
166181
The CDK `a11y` package comes with a set of CSS styles that can be used when building accessible
167182
components. To take advantage of them, you have to include the styles in your global stylesheet.
168183
If 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+
177193
By 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,
179195
while keeping it available for assistive technology. You can do so using the `cdk-visually-hidden`
180196
class:
181197

@@ -185,7 +201,8 @@ class:
185201
</div>
186202
```
187203

188-
### Targeting high contrast users
204+
#### Targeting high contrast users
205+
189206
The `a11y` package offers a mixin that allows you to target users that have the Windows high
190207
contrast 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`

src/cdk/a11y/focus-trap/focus-trap.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
### FocusTrap
2+
23
The `cdkTrapFocus` directive traps <kbd>Tab</kbd> key focus within an element. This is intended to
34
be used to create accessible experience for components like
45
[modal dialogs](https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal), where focus must be
@@ -7,6 +8,7 @@ constrained.
78
This directive is declared in `A11yModule`.
89

910
#### Example
11+
1012
```html
1113
<div class="my-inner-dialog-content" cdkTrapFocus>
1214
<!-- Tab and Shift + Tab will not leave this element. -->

0 commit comments

Comments
 (0)