Skip to content

Commit 0a22e0f

Browse files
crisbetojelbourn
authored andcommitted
fix(datepicker): label state not being updated in some cases (#19761)
The date range input wasn't emitting to its `stateChanges` stream when typing in the sub-inputs which meant that in some cases the view state was out of sync. These changes add an extra call to ensure that everything is synced up.
1 parent cf53a70 commit 0a22e0f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/material/datepicker/date-range-input.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,21 @@ describe('MatDateRangeInput', () => {
527527
expect(fixture.componentInstance.rangeInput.placeholder).toBe('Start date – End date');
528528
});
529529

530+
it('should emit to the stateChanges stream when typing a value into an input', () => {
531+
const fixture = createComponent(StandardRangePicker);
532+
fixture.detectChanges();
533+
const {start, rangeInput} = fixture.componentInstance;
534+
const spy = jasmine.createSpy('stateChanges spy');
535+
const subscription = rangeInput.stateChanges.subscribe(spy);
536+
537+
start.nativeElement.value = '10/10/2020';
538+
dispatchFakeEvent(start.nativeElement, 'input');
539+
fixture.detectChanges();
540+
541+
expect(spy).toHaveBeenCalled();
542+
subscription.unsubscribe();
543+
});
544+
530545
});
531546

532547
@Component({

src/material/datepicker/date-range-input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ export class MatDateRangeInput<D> implements MatFormFieldControl<DateRange<D>>,
291291

292292
/** Handles the value in one of the child inputs changing. */
293293
_handleChildValueChange() {
294+
this.stateChanges.next();
294295
this._changeDetectorRef.markForCheck();
295296
}
296297

0 commit comments

Comments
 (0)