Skip to content

Commit 21e9768

Browse files
mmalerbatinayuangao
authored andcommitted
fix(datepicker): mark input tocuhed on calendar date selected (#6007)
* fix(datepicker): mark input tocuhed on calendar date selected * add test
1 parent 3c19234 commit 21e9768

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/lib/datepicker/datepicker-input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export class MdDatepickerInput<D> implements AfterContentInit, ControlValueAcces
212212
this._datepicker.selectedChanged.subscribe((selected: D) => {
213213
this.value = selected;
214214
this._cvaOnChange(selected);
215+
this._onTouched();
215216
this.dateInput.emit(new MdDatepickerInputEvent(this, this._elementRef.nativeElement));
216217
this.dateChange.emit(new MdDatepickerInputEvent(this, this._elementRef.nativeElement));
217218
});

src/lib/datepicker/datepicker.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,21 @@ describe('MdDatepicker', () => {
411411

412412
expect(inputEl.classList).toContain('ng-touched');
413413
});
414+
415+
it('should mark input touched on calendar selection', () => {
416+
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
417+
418+
expect(inputEl.classList).toContain('ng-untouched');
419+
420+
testComponent.datepicker._selectAndClose(new Date(2017, JAN, 1));
421+
fixture.detectChanges();
422+
423+
fixture.whenStable().then(() => {
424+
fixture.detectChanges();
425+
426+
expect(inputEl.classList).toContain('ng-touched');
427+
});
428+
});
414429
});
415430

416431
describe('datepicker with formControl', () => {

0 commit comments

Comments
 (0)