Skip to content

Commit

Permalink
docs(cdk/a11y): add example of LiveAnnouncer inside dialog (#27944)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
zarend committed Oct 17, 2023
1 parent 7a8b7da commit ff32b51
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/dev-app/live-announcer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ ng_module(
deps = [
"//src/cdk/a11y",
"//src/material/button",
"//src/material/dialog",
],
)
26 changes: 24 additions & 2 deletions src/dev-app/live-announcer/live-announcer-demo.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
<div>
<p>
<button
mat-raised-button
color="primary"
(click)="announceText('Hey Google')">Announce Text</button>
</div>
</p>
<p>
<button
mat-raised-button
color="primary"
(click)="openDialog()">Open Dialog</button>
</p>

<ng-template let-data let-dialogRef="dialogRef">
<h2>Live Announcer Test Dialog</h2>
<p>Test LiveAnnouncer inside an aria modal.</p>
<p>
<button
mat-raised-button
color="primary"
(click)="announceText('Hey Google')">Announce Text</button>
</p>
<button type="button" cdkFocusInitial
mat-button
(click)="dialogRef.close()">
Close
</button>
</ng-template>
13 changes: 11 additions & 2 deletions src/dev-app/live-announcer/live-announcer-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Component} from '@angular/core';
import {Component, TemplateRef, ViewChild} from '@angular/core';
import {A11yModule, LiveAnnouncer} from '@angular/cdk/a11y';
import {MatButtonModule} from '@angular/material/button';
import {MatDialog} from '@angular/material/dialog';

@Component({
selector: 'toolbar-demo',
Expand All @@ -17,9 +18,17 @@ import {MatButtonModule} from '@angular/material/button';
imports: [A11yModule, MatButtonModule],
})
export class LiveAnnouncerDemo {
constructor(private _liveAnnouncer: LiveAnnouncer) {}
constructor(
private _liveAnnouncer: LiveAnnouncer,
public dialog: MatDialog,
) {}

announceText(message: string) {
this._liveAnnouncer.announce(message);
}

@ViewChild(TemplateRef) template: TemplateRef<any>;
openDialog() {
this.dialog.open(this.template);
}
}

0 comments on commit ff32b51

Please sign in to comment.