@@ -272,27 +272,23 @@ describe('MatDatepicker', () => {
272272 expect ( popup . getAttribute ( 'role' ) ) . toBe ( 'dialog' ) ;
273273 } ) ) ;
274274
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 ( ) ;
280277
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' ) ;
283280
284- testComponent . datepicker . open ( ) ;
285- fixture . detectChanges ( ) ;
286- tick ( ) ;
287- flush ( ) ;
281+ testComponent . datepicker . open ( ) ;
282+ fixture . detectChanges ( ) ;
283+ tick ( ) ;
284+ flush ( ) ;
288285
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+ } ) ) ;
296292
297293 it ( 'close should close dialog' , fakeAsync ( ( ) => {
298294 testComponent . touch = true ;
@@ -1449,6 +1445,26 @@ describe('MatDatepicker', () => {
14491445
14501446 expect ( toggle . classList ) . not . toContain ( 'mat-datepicker-toggle-active' ) ;
14511447 } ) ) ;
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+ } ) ) ;
14521468 } ) ;
14531469
14541470 describe ( 'datepicker with custom mat-datepicker-toggle icon' , ( ) => {
@@ -2183,6 +2199,14 @@ describe('MatDatepicker', () => {
21832199 expect ( toggle . hasAttribute ( 'aria-haspopup' ) ) . toBe ( false ) ;
21842200 } ) ;
21852201
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+
21862210 it ( 'should not throw on init if input does not have a datepicker' , ( ) => {
21872211 expect ( ( ) => {
21882212 const fixture = createComponent ( DatepickerInputWithNoDatepicker , [ MatNativeDateModule ] ) ;
0 commit comments