@@ -272,27 +272,23 @@ describe('MatDatepicker', () => {
272
272
expect ( popup . getAttribute ( 'role' ) ) . toBe ( 'dialog' ) ;
273
273
} ) ) ;
274
274
275
- it (
276
- 'should set aria-labelledby to the one from the input, if not placed inside ' +
277
- 'a mat-form-field' ,
278
- fakeAsync ( ( ) => {
279
- expect ( fixture . nativeElement . querySelector ( 'mat-form-field' ) ) . toBeFalsy ( ) ;
275
+ it ( 'should set aria-labelledby to the one from the input, if not placed inside a mat-form-field' , fakeAsync ( ( ) => {
276
+ expect ( fixture . nativeElement . querySelector ( 'mat-form-field' ) ) . toBeFalsy ( ) ;
280
277
281
- const input : HTMLInputElement = fixture . nativeElement . querySelector ( 'input' ) ;
282
- input . setAttribute ( 'aria-labelledby' , 'test-label' ) ;
278
+ const input : HTMLInputElement = fixture . nativeElement . querySelector ( 'input' ) ;
279
+ input . setAttribute ( 'aria-labelledby' , 'test-label' ) ;
283
280
284
- testComponent . datepicker . open ( ) ;
285
- fixture . detectChanges ( ) ;
286
- tick ( ) ;
287
- flush ( ) ;
281
+ testComponent . datepicker . open ( ) ;
282
+ fixture . detectChanges ( ) ;
283
+ tick ( ) ;
284
+ flush ( ) ;
288
285
289
- const popup = document . querySelector (
290
- '.cdk-overlay-pane .mat-datepicker-content-container' ,
291
- ) ! ;
292
- expect ( popup ) . toBeTruthy ( ) ;
293
- expect ( popup . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'test-label' ) ;
294
- } ) ,
295
- ) ;
286
+ const popup = document . querySelector (
287
+ '.cdk-overlay-pane .mat-datepicker-content-container' ,
288
+ ) ! ;
289
+ expect ( popup ) . toBeTruthy ( ) ;
290
+ expect ( popup . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'test-label' ) ;
291
+ } ) ) ;
296
292
297
293
it ( 'close should close dialog' , fakeAsync ( ( ) => {
298
294
testComponent . touch = true ;
@@ -1444,6 +1440,26 @@ describe('MatDatepicker', () => {
1444
1440
1445
1441
expect ( toggle . classList ) . not . toContain ( 'mat-datepicker-toggle-active' ) ;
1446
1442
} ) ) ;
1443
+
1444
+ it ( 'should set aria-expanded on the toggle' , fakeAsync ( ( ) => {
1445
+ const button = fixture . nativeElement . querySelector ( 'mat-datepicker-toggle button' ) ;
1446
+
1447
+ expect ( button . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
1448
+
1449
+ fixture . componentInstance . datepicker . open ( ) ;
1450
+ fixture . detectChanges ( ) ;
1451
+ tick ( ) ;
1452
+ flush ( ) ;
1453
+
1454
+ expect ( button . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
1455
+
1456
+ fixture . componentInstance . datepicker . close ( ) ;
1457
+ fixture . detectChanges ( ) ;
1458
+ flush ( ) ;
1459
+ fixture . detectChanges ( ) ;
1460
+
1461
+ expect ( button . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
1462
+ } ) ) ;
1447
1463
} ) ;
1448
1464
1449
1465
describe ( 'datepicker with custom mat-datepicker-toggle icon' , ( ) => {
@@ -2178,6 +2194,14 @@ describe('MatDatepicker', () => {
2178
2194
expect ( toggle . hasAttribute ( 'aria-haspopup' ) ) . toBe ( false ) ;
2179
2195
} ) ;
2180
2196
2197
+ it ( 'should not set aria-expanded if toggle does not have a datepicker' , ( ) => {
2198
+ const fixture = createComponent ( DatepickerToggleWithNoDatepicker , [ MatNativeDateModule ] ) ;
2199
+ fixture . detectChanges ( ) ;
2200
+ const toggle = fixture . nativeElement . querySelector ( '.mat-datepicker-toggle button' ) ;
2201
+
2202
+ expect ( toggle . hasAttribute ( 'aria-expanded' ) ) . toBe ( false ) ;
2203
+ } ) ;
2204
+
2181
2205
it ( 'should not throw on init if input does not have a datepicker' , ( ) => {
2182
2206
expect ( ( ) => {
2183
2207
const fixture = createComponent ( DatepickerInputWithNoDatepicker , [ MatNativeDateModule ] ) ;
0 commit comments