7
7
*/
8
8
9
9
import { Direction , Directionality } from '@angular/cdk/bidi' ;
10
+ import { LiveAnnouncer } from '@angular/cdk/a11y' ;
10
11
import {
11
12
ChangeDetectionStrategy ,
12
13
ChangeDetectorRef ,
@@ -56,6 +57,7 @@ export class DevAppLayout {
56
57
private _document = inject ( DOCUMENT ) ;
57
58
private _iconRegistry = inject ( MatIconRegistry ) ;
58
59
private _route = inject ( ActivatedRoute ) ;
60
+ private _liveAnnouncer = inject ( LiveAnnouncer ) ;
59
61
60
62
state = getAppState ( ) ;
61
63
testMode : Observable < boolean > ;
@@ -161,33 +163,43 @@ export class DevAppLayout {
161
163
this . state . darkTheme = value ;
162
164
this . _document . body . classList . toggle ( 'demo-unicorn-dark-theme' , value ) ;
163
165
setAppState ( this . state ) ;
166
+ this . _liveAnnouncer . announce ( value ? 'Dark theme enabled.' : 'Light theme enabled.' ) ;
164
167
}
165
168
166
169
toggleSystemTheme ( value = ! this . state . systemTheme ) {
167
170
this . state . systemTheme = value ;
168
171
this . _document . body . classList . toggle ( 'demo-experimental-theme' , value ) ;
169
172
setAppState ( this . state ) ;
173
+ this . _liveAnnouncer . announce ( value ? 'System theme enabled.' : 'Standard theme enabled.' ) ;
170
174
}
171
175
172
176
toggleFullscreen ( ) {
173
177
this . _element . nativeElement . querySelector ( '.demo-content' ) ?. requestFullscreen ( ) ;
178
+ this . _liveAnnouncer . announce ( 'Fullscreen toggled.' ) ;
174
179
}
175
180
176
181
toggleStrongFocus ( value = ! this . state . strongFocusEnabled ) {
177
182
this . state . strongFocusEnabled = value ;
178
183
this . _document . body . classList . toggle ( 'demo-strong-focus' , value ) ;
179
184
setAppState ( this . state ) ;
185
+ this . _liveAnnouncer . announce ( value ? 'Strong focus enabled.' : 'Strong focus disabled.' ) ;
180
186
}
181
187
182
- toggleZoneless ( value = ! this . isZoneless ) {
188
+ async toggleZoneless ( value = ! this . isZoneless ) {
183
189
this . state . zoneless = value ;
184
190
setAppState ( this . state ) ;
191
+ const message = value ? 'Zoneless enabled, reloading.' : 'Zoned enabled, reloading.' ;
192
+ await this . _liveAnnouncer . announce ( message ) ;
185
193
location . reload ( ) ;
186
194
}
187
195
188
- toggleAnimations ( ) {
196
+ async toggleAnimations ( ) {
189
197
this . state . animations = ! this . state . animations ;
190
198
setAppState ( this . state ) ;
199
+ const message = this . state . animations
200
+ ? 'Animations enabled, reloading.'
201
+ : 'Animations disabled, reloading.' ;
202
+ await this . _liveAnnouncer . announce ( message ) ;
191
203
location . reload ( ) ;
192
204
}
193
205
@@ -198,6 +210,7 @@ export class DevAppLayout {
198
210
199
211
this . state . density = this . _densityScales [ index ] ;
200
212
setAppState ( this . state ) ;
213
+ this . _liveAnnouncer . announce ( `Density set to ${ this . state . density } ` ) ;
201
214
202
215
// Keep the tooltip open so we can see what the density was changed to. Ideally we'd
203
216
// always show the density in a badge, but the M2 badge is too large for the toolbar.
@@ -209,13 +222,17 @@ export class DevAppLayout {
209
222
toggleRippleDisabled ( value = ! this . state . rippleDisabled ) {
210
223
this . _rippleOptions . disabled = this . state . rippleDisabled = value ;
211
224
setAppState ( this . state ) ;
225
+ this . _liveAnnouncer . announce ( value ? 'Ripples disabled.' : 'Ripples enabled.' ) ;
212
226
}
213
227
214
228
toggleDirection ( value : Direction = this . state . direction === 'ltr' ? 'rtl' : 'ltr' ) {
215
229
if ( value !== this . _dir . value ) {
216
230
this . _dir . value = this . state . direction = value ;
217
231
this . _changeDetectorRef . markForCheck ( ) ;
218
232
setAppState ( this . state ) ;
233
+ this . _liveAnnouncer . announce (
234
+ value === 'ltr' ? 'Direction set to LTR.' : 'Direction set to RTL.' ,
235
+ ) ;
219
236
}
220
237
}
221
238
@@ -232,12 +249,16 @@ export class DevAppLayout {
232
249
) ;
233
250
this . state . m3Enabled = value ;
234
251
setAppState ( this . state ) ;
252
+ this . _liveAnnouncer . announce ( value ? 'Using M3 theme.' : 'Using M2 theme.' ) ;
235
253
}
236
254
237
255
toggleColorApiBackCompat ( value = ! this . state . colorApiBackCompat ) {
238
256
this . state . colorApiBackCompat = value ;
239
257
this . _document . body . classList . toggle ( 'demo-color-api-back-compat' , value ) ;
240
258
setAppState ( this . state ) ;
259
+ this . _liveAnnouncer . announce (
260
+ value ? 'Color API back-compatibility enabled.' : 'Color API back-compatibility disabled.' ,
261
+ ) ;
241
262
}
242
263
243
264
getDensityClass ( ) {
0 commit comments