Skip to content

Commit

Permalink
fix(module:date-picker): ng-untouched when loose focus (#7922)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicoss54 committed May 9, 2023
1 parent 59143d2 commit 9ebcf72
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions components/date-picker/date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ describe('NzDatePickerComponent', () => {
expect(getPickerContainer()).toBeNull();
}));

it('should mark the control touched when user loseFocus of datePicker', fakeAsync(() => {
fixtureInstance.useSuite = 4;
fixtureInstance.control = new FormControl<Date | null>(null);
fixture.detectChanges();
flush();
const datePickerElement = fixture.debugElement.query(By.directive(NzDatePickerComponent)).nativeElement;
openPickerByClickTrigger();
expect(datePickerElement.classList).toContain('ng-untouched');
triggerInputBlur();
fixture.detectChanges();
flush();
expect(datePickerElement.classList).toContain('ng-touched');
expect(fixtureInstance.control.touched).toBeTruthy();
}));

it('should support nzInputReadOnly', fakeAsync(() => {
fixtureInstance.nzInputReadOnly = true;
fixture.detectChanges();
Expand Down
1 change: 1 addition & 0 deletions components/date-picker/date-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, AfterViewInit,
// blur event has not the relatedTarget in IE11, use focusout instead.
onFocusout(event: FocusEvent): void {
event.preventDefault();
this.onTouchedFn();
if (!this.elementRef.nativeElement.contains(<Node>event.relatedTarget)) {
this.checkAndClose();
}
Expand Down

0 comments on commit 9ebcf72

Please sign in to comment.