Skip to content

Commit ff32b51

Browse files
committed
docs(cdk/a11y): add example of LiveAnnouncer inside dialog (#27944)
Update the live-announcer demo in the dev-app. Add an example of calling LiveAnnouncer inside of a Dialog. Create another way to reproduce issues with using live regions inside an aria-modal (#22733). (cherry picked from commit 504ff7f)
1 parent 7a8b7da commit ff32b51

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/dev-app/live-announcer/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ ng_module(
99
deps = [
1010
"//src/cdk/a11y",
1111
"//src/material/button",
12+
"//src/material/dialog",
1213
],
1314
)
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1-
<div>
1+
<p>
22
<button
33
mat-raised-button
44
color="primary"
55
(click)="announceText('Hey Google')">Announce Text</button>
6-
</div>
6+
</p>
7+
<p>
8+
<button
9+
mat-raised-button
10+
color="primary"
11+
(click)="openDialog()">Open Dialog</button>
12+
</p>
13+
14+
<ng-template let-data let-dialogRef="dialogRef">
15+
<h2>Live Announcer Test Dialog</h2>
16+
<p>Test LiveAnnouncer inside an aria modal.</p>
17+
<p>
18+
<button
19+
mat-raised-button
20+
color="primary"
21+
(click)="announceText('Hey Google')">Announce Text</button>
22+
</p>
23+
<button type="button" cdkFocusInitial
24+
mat-button
25+
(click)="dialogRef.close()">
26+
Close
27+
</button>
28+
</ng-template>

src/dev-app/live-announcer/live-announcer-demo.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Component} from '@angular/core';
9+
import {Component, TemplateRef, ViewChild} from '@angular/core';
1010
import {A11yModule, LiveAnnouncer} from '@angular/cdk/a11y';
1111
import {MatButtonModule} from '@angular/material/button';
12+
import {MatDialog} from '@angular/material/dialog';
1213

1314
@Component({
1415
selector: 'toolbar-demo',
@@ -17,9 +18,17 @@ import {MatButtonModule} from '@angular/material/button';
1718
imports: [A11yModule, MatButtonModule],
1819
})
1920
export class LiveAnnouncerDemo {
20-
constructor(private _liveAnnouncer: LiveAnnouncer) {}
21+
constructor(
22+
private _liveAnnouncer: LiveAnnouncer,
23+
public dialog: MatDialog,
24+
) {}
2125

2226
announceText(message: string) {
2327
this._liveAnnouncer.announce(message);
2428
}
29+
30+
@ViewChild(TemplateRef) template: TemplateRef<any>;
31+
openDialog() {
32+
this.dialog.open(this.template);
33+
}
2534
}

0 commit comments

Comments
 (0)