diff --git a/components/date-picker/date-picker.component.spec.ts b/components/date-picker/date-picker.component.spec.ts index 9c21d79160..7e638c2c1b 100644 --- a/components/date-picker/date-picker.component.spec.ts +++ b/components/date-picker/date-picker.component.spec.ts @@ -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; @@ -1143,6 +1149,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'); } diff --git a/components/date-picker/date-picker.component.ts b/components/date-picker/date-picker.component.ts index 3e4ce081b1..d9a914a90f 100644 --- a/components/date-picker/date-picker.component.ts +++ b/components/date-picker/date-picker.component.ts @@ -458,6 +458,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte this.updateInputWidthAndArrowLeft(); this.overlayOpen = true; this.nzOnOpenChange.emit(true); + this.focus(); this.cdr.markForCheck(); } }