@@ -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 ;
@@ -1449,6 +1445,26 @@ describe('MatDatepicker', () => {
1449
1445
1450
1446
expect ( toggle . classList ) . not . toContain ( 'mat-datepicker-toggle-active' ) ;
1451
1447
} ) ) ;
1448
+
1449
+ it ( 'should set aria-expanded on the toggle' , fakeAsync ( ( ) => {
1450
+ const button = fixture . nativeElement . querySelector ( 'mat-datepicker-toggle button' ) ;
1451
+
1452
+ expect ( button . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
1453
+
1454
+ fixture . componentInstance . datepicker . open ( ) ;
1455
+ fixture . detectChanges ( ) ;
1456
+ tick ( ) ;
1457
+ flush ( ) ;
1458
+
1459
+ expect ( button . getAttribute ( 'aria-expanded' ) ) . toBe ( 'true' ) ;
1460
+
1461
+ fixture . componentInstance . datepicker . close ( ) ;
1462
+ fixture . detectChanges ( ) ;
1463
+ flush ( ) ;
1464
+ fixture . detectChanges ( ) ;
1465
+
1466
+ expect ( button . getAttribute ( 'aria-expanded' ) ) . toBe ( 'false' ) ;
1467
+ } ) ) ;
1452
1468
} ) ;
1453
1469
1454
1470
describe ( 'datepicker with custom mat-datepicker-toggle icon' , ( ) => {
@@ -2183,6 +2199,14 @@ describe('MatDatepicker', () => {
2183
2199
expect ( toggle . hasAttribute ( 'aria-haspopup' ) ) . toBe ( false ) ;
2184
2200
} ) ;
2185
2201
2202
+ it ( 'should not set aria-expanded if toggle does not have a datepicker' , ( ) => {
2203
+ const fixture = createComponent ( DatepickerToggleWithNoDatepicker , [ MatNativeDateModule ] ) ;
2204
+ fixture . detectChanges ( ) ;
2205
+ const toggle = fixture . nativeElement . querySelector ( '.mat-datepicker-toggle button' ) ;
2206
+
2207
+ expect ( toggle . hasAttribute ( 'aria-expanded' ) ) . toBe ( false ) ;
2208
+ } ) ;
2209
+
2186
2210
it ( 'should not throw on init if input does not have a datepicker' , ( ) => {
2187
2211
expect ( ( ) => {
2188
2212
const fixture = createComponent ( DatepickerInputWithNoDatepicker , [ MatNativeDateModule ] ) ;
0 commit comments