Skip to content

Commit 74c13a4

Browse files
authored
fix(module:time-picker): modelChange trigger twice (#7902)
1 parent 3d1c8b6 commit 74c13a4

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

components/time-picker/time-picker.component.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ describe('time-picker', () => {
319319
fixture.detectChanges();
320320
expect(fixture.debugElement.query(By.css(`.ant-picker-borderless`))).toBeDefined();
321321
}));
322+
it('should not trigger blur after close panel', fakeAsync(() => {
323+
dispatchMouseEvent(getPickerInput(fixture.debugElement), 'click');
324+
fixture.detectChanges();
325+
tick(500);
326+
fixture.detectChanges();
327+
expect(getPickerContainer()).not.toBeNull();
328+
329+
const okButton = getPickerOkButton(fixture.debugElement);
330+
expect(okButton).not.toBeNull();
331+
dispatchFakeEvent(okButton, 'click');
332+
fixture.detectChanges();
333+
tick(500);
334+
fixture.detectChanges();
335+
336+
expect(timeElement.nativeElement.querySelector('input') === document.activeElement).toBe(false);
337+
}));
322338
describe('setup I18n service', () => {
323339
let srv: NzI18nService;
324340

components/time-picker/time-picker.component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'timePicker';
115115
[nzAllowEmpty]="nzAllowEmpty"
116116
[(ngModel)]="value"
117117
(ngModelChange)="onPanelValueChange($event)"
118-
(closePanel)="setCurrentValueAndClose()"
118+
(closePanel)="closePanel()"
119119
></nz-time-picker-panel>
120120
</div>
121121
</div>
@@ -332,6 +332,10 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
332332
this.focus();
333333
}
334334

335+
closePanel(): void {
336+
this.inputRef.nativeElement.blur();
337+
}
338+
335339
setCurrentValueAndClose(): void {
336340
this.emitValue(this.value);
337341
this.close();

0 commit comments

Comments
 (0)