Skip to content

Commit c9842eb

Browse files
committed
docs(multiple): adds live announcer to improve layout button toggles
Updates buttons in the header of the dev-app layout and improves accessibility by adding live announcer to announce the action that was triggered. Fixes b/435507181
1 parent 29f0bb2 commit c9842eb

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import {Direction, Directionality} from '@angular/cdk/bidi';
10+
import {LiveAnnouncer} from '@angular/cdk/a11y';
1011
import {
1112
ChangeDetectionStrategy,
1213
ChangeDetectorRef,
@@ -56,6 +57,7 @@ export class DevAppLayout {
5657
private _document = inject(DOCUMENT);
5758
private _iconRegistry = inject(MatIconRegistry);
5859
private _route = inject(ActivatedRoute);
60+
private _liveAnnouncer = inject(LiveAnnouncer);
5961

6062
state = getAppState();
6163
testMode: Observable<boolean>;
@@ -161,33 +163,43 @@ export class DevAppLayout {
161163
this.state.darkTheme = value;
162164
this._document.body.classList.toggle('demo-unicorn-dark-theme', value);
163165
setAppState(this.state);
166+
this._liveAnnouncer.announce(value ? 'Dark theme enabled.' : 'Light theme enabled.');
164167
}
165168

166169
toggleSystemTheme(value = !this.state.systemTheme) {
167170
this.state.systemTheme = value;
168171
this._document.body.classList.toggle('demo-experimental-theme', value);
169172
setAppState(this.state);
173+
this._liveAnnouncer.announce(value ? 'System theme enabled.' : 'Standard theme enabled.');
170174
}
171175

172176
toggleFullscreen() {
173177
this._element.nativeElement.querySelector('.demo-content')?.requestFullscreen();
178+
this._liveAnnouncer.announce('Fullscreen toggled.');
174179
}
175180

176181
toggleStrongFocus(value = !this.state.strongFocusEnabled) {
177182
this.state.strongFocusEnabled = value;
178183
this._document.body.classList.toggle('demo-strong-focus', value);
179184
setAppState(this.state);
185+
this._liveAnnouncer.announce(value ? 'Strong focus enabled.' : 'Strong focus disabled.');
180186
}
181187

182-
toggleZoneless(value = !this.isZoneless) {
188+
async toggleZoneless(value = !this.isZoneless) {
183189
this.state.zoneless = value;
184190
setAppState(this.state);
191+
const message = value ? 'Zoneless enabled, reloading.' : 'Zoned enabled, reloading.';
192+
await this._liveAnnouncer.announce(message);
185193
location.reload();
186194
}
187195

188-
toggleAnimations() {
196+
async toggleAnimations() {
189197
this.state.animations = !this.state.animations;
190198
setAppState(this.state);
199+
const message = this.state.animations
200+
? 'Animations enabled, reloading.'
201+
: 'Animations disabled, reloading.';
202+
await this._liveAnnouncer.announce(message);
191203
location.reload();
192204
}
193205

@@ -198,6 +210,7 @@ export class DevAppLayout {
198210

199211
this.state.density = this._densityScales[index];
200212
setAppState(this.state);
213+
this._liveAnnouncer.announce(`Density set to ${this.state.density}`);
201214

202215
// Keep the tooltip open so we can see what the density was changed to. Ideally we'd
203216
// always show the density in a badge, but the M2 badge is too large for the toolbar.
@@ -209,13 +222,17 @@ export class DevAppLayout {
209222
toggleRippleDisabled(value = !this.state.rippleDisabled) {
210223
this._rippleOptions.disabled = this.state.rippleDisabled = value;
211224
setAppState(this.state);
225+
this._liveAnnouncer.announce(value ? 'Ripples disabled.' : 'Ripples enabled.');
212226
}
213227

214228
toggleDirection(value: Direction = this.state.direction === 'ltr' ? 'rtl' : 'ltr') {
215229
if (value !== this._dir.value) {
216230
this._dir.value = this.state.direction = value;
217231
this._changeDetectorRef.markForCheck();
218232
setAppState(this.state);
233+
this._liveAnnouncer.announce(
234+
value === 'ltr' ? 'Direction set to LTR.' : 'Direction set to RTL.',
235+
);
219236
}
220237
}
221238

@@ -232,12 +249,16 @@ export class DevAppLayout {
232249
);
233250
this.state.m3Enabled = value;
234251
setAppState(this.state);
252+
this._liveAnnouncer.announce(value ? 'Using M3 theme.' : 'Using M2 theme.');
235253
}
236254

237255
toggleColorApiBackCompat(value = !this.state.colorApiBackCompat) {
238256
this.state.colorApiBackCompat = value;
239257
this._document.body.classList.toggle('demo-color-api-back-compat', value);
240258
setAppState(this.state);
259+
this._liveAnnouncer.announce(
260+
value ? 'Color API back-compatibility enabled.' : 'Color API back-compatibility disabled.',
261+
);
241262
}
242263

243264
getDensityClass() {

0 commit comments

Comments
 (0)