@@ -10,7 +10,7 @@ import {
10
10
} from '@angular/cdk/testing' ;
11
11
import { Component , NgZone } from '@angular/core' ;
12
12
import { ComponentFixture , TestBed , async , inject } from '@angular/core/testing' ;
13
- import { DEC , FEB , JAN , MatNativeDateModule , NOV } from '@angular/material/core' ;
13
+ import { DEC , FEB , JAN , MatNativeDateModule , NOV , JUL } from '@angular/material/core' ;
14
14
import { By } from '@angular/platform-browser' ;
15
15
import { Direction , Directionality } from '@angular/cdk/bidi' ;
16
16
import { MatCalendar } from './calendar' ;
@@ -32,6 +32,7 @@ describe('MatCalendar', () => {
32
32
StandardCalendar ,
33
33
CalendarWithMinMax ,
34
34
CalendarWithDateFilter ,
35
+ CalendarWithSelectableMinDate ,
35
36
] ,
36
37
providers : [
37
38
MatDatepickerIntl ,
@@ -399,6 +400,37 @@ describe('MatCalendar', () => {
399
400
400
401
expect ( calendarInstance . multiYearView . _init ) . toHaveBeenCalled ( ) ;
401
402
} ) ;
403
+
404
+ it ( 'should update the minDate in the child view if it changed after an interaction' , ( ) => {
405
+ fixture . destroy ( ) ;
406
+
407
+ const dynamicFixture = TestBed . createComponent ( CalendarWithSelectableMinDate ) ;
408
+ dynamicFixture . detectChanges ( ) ;
409
+
410
+ const calendarDebugElement = dynamicFixture . debugElement . query ( By . directive ( MatCalendar ) ) ;
411
+ const disabledClass = 'mat-calendar-body-disabled' ;
412
+ calendarElement = calendarDebugElement . nativeElement ;
413
+ calendarInstance = calendarDebugElement . componentInstance ;
414
+
415
+ let cells = Array . from ( calendarElement . querySelectorAll ( '.mat-calendar-body-cell' ) ) ;
416
+
417
+ expect ( cells . slice ( 0 , 9 ) . every ( c => c . classList . contains ( disabledClass ) ) )
418
+ . toBe ( true , 'Expected dates up to the 10th to be disabled.' ) ;
419
+
420
+ expect ( cells . slice ( 9 ) . every ( c => c . classList . contains ( disabledClass ) ) )
421
+ . toBe ( false , 'Expected dates after the 10th to be enabled.' ) ;
422
+
423
+ ( cells [ 14 ] as HTMLElement ) . click ( ) ;
424
+ dynamicFixture . detectChanges ( ) ;
425
+ cells = Array . from ( calendarElement . querySelectorAll ( '.mat-calendar-body-cell' ) ) ;
426
+
427
+ expect ( cells . slice ( 0 , 14 ) . every ( c => c . classList . contains ( disabledClass ) ) )
428
+ . toBe ( true , 'Expected dates up to the 14th to be disabled.' ) ;
429
+
430
+ expect ( cells . slice ( 14 ) . every ( c => c . classList . contains ( disabledClass ) ) )
431
+ . toBe ( false , 'Expected dates after the 14th to be enabled.' ) ;
432
+ } ) ;
433
+
402
434
} ) ;
403
435
404
436
describe ( 'calendar with date filter' , ( ) => {
@@ -521,3 +553,28 @@ class CalendarWithDateFilter {
521
553
return ! ( date . getDate ( ) % 2 ) && date . getMonth ( ) !== NOV ;
522
554
}
523
555
}
556
+
557
+
558
+ @Component ( {
559
+ template : `
560
+ <mat-calendar
561
+ [startAt]="startAt"
562
+ (selectedChange)="select($event)"
563
+ [selected]="selected"
564
+ [minDate]="selected">
565
+ </mat-calendar>
566
+ `
567
+ } )
568
+ class CalendarWithSelectableMinDate {
569
+ startAt = new Date ( 2018 , JUL , 0 ) ;
570
+ selected : Date ;
571
+ minDate : Date ;
572
+
573
+ constructor ( ) {
574
+ this . select ( new Date ( 2018 , JUL , 10 ) ) ;
575
+ }
576
+
577
+ select ( value : Date ) {
578
+ this . minDate = this . selected = value ;
579
+ }
580
+ }
0 commit comments