Skip to content

Commit

Permalink
fix(module:datepicker): focus input when opened programmatically (#7512)
Browse files Browse the repository at this point in the history
Co-authored-by: Sébastien Cambon <sebastiencambon&hotmail.com>
  • Loading branch information
sebcam committed Jul 11, 2022
1 parent a652470 commit b3a27d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions components/date-picker/date-picker.component.spec.ts
Expand Up @@ -159,6 +159,12 @@ describe('NzDatePickerComponent', () => {
expect(getPickerContainer()).not.toBeNull();
}));

it('should have focus when opened progammatically', fakeAsync(() => {
fixture.detectChanges();
openPickerByCode();
expect(document.activeElement).toEqual(getPickerInput(fixture.debugElement));
}));

it('should open by click and close by tab', fakeAsync(() => {
const nzOnChange = spyOn(fixtureInstance, 'nzOnChange');
fixtureInstance.useSuite = 5;
Expand Down Expand Up @@ -1189,6 +1195,13 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
}

function openPickerByCode(): void {
fixtureInstance.datePicker.open();
fixture.detectChanges();
tick(500);
fixture.detectChanges();
}

function triggerInputBlur(): void {
dispatchFakeEvent(getPickerInput(fixture.debugElement), 'focusout');
}
Expand Down
1 change: 1 addition & 0 deletions components/date-picker/date-picker.component.ts
Expand Up @@ -432,6 +432,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte
this.updateInputWidthAndArrowLeft();
this.overlayOpen = true;
this.nzOnOpenChange.emit(true);
this.focus();
this.cdr.markForCheck();
}
}
Expand Down

0 comments on commit b3a27d8

Please sign in to comment.