From 85fceb50bdd8f19b7275ba4e55acddcd2e7377ef Mon Sep 17 00:00:00 2001 From: luckyship <304093931@qq.com> Date: Thu, 13 Oct 2022 12:45:02 +0800 Subject: [PATCH] fix(module:date-picker): fix datePicker can't clear (#7671) close #7534 --- components/date-picker/date-picker.component.ts | 1 + .../date-picker/range-picker.component.spec.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/components/date-picker/date-picker.component.ts b/components/date-picker/date-picker.component.ts index 8e985e4bcb..6098f9a19e 100644 --- a/components/date-picker/date-picker.component.ts +++ b/components/date-picker/date-picker.component.ts @@ -801,6 +801,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte const newValue: CompatibleValue = this.datePickerService.makeValue(value); this.datePickerService.setValue(newValue); this.datePickerService.initialValue = newValue; + this.cdr.detectChanges(); } renderClass(value: boolean): void { diff --git a/components/date-picker/range-picker.component.spec.ts b/components/date-picker/range-picker.component.spec.ts index dc3c573b03..583f5c25d0 100644 --- a/components/date-picker/range-picker.component.spec.ts +++ b/components/date-picker/range-picker.component.spec.ts @@ -161,6 +161,19 @@ describe('NzRangePickerComponent', () => { expect(debugElement.query(clearBtnSelector)).toBeFalsy(); })); + it('should support clear input value when set default value', fakeAsync(() => { + const clearBtnSelector = By.css(`.${PREFIX_CLASS}-clear`); + fixtureInstance.modelValue = [new Date(), new Date()]; + fixtureInstance.nzAllowClear = true; + tick(); + fixture.autoDetectChanges(); + + const leftInput = getPickerInput(fixture.debugElement); + tick(500); + debugElement.query(clearBtnSelector).nativeElement.click(); + expect(leftInput.attributes.getNamedItem('ng-reflect-model')?.value).toBeUndefined(); + })); + it('should support nzAutoFocus', fakeAsync(() => { fixtureInstance.nzAutoFocus = true; fixture.detectChanges();