Skip to content

Commit ba90876

Browse files
authored
fix(module:date-picker): fix datePicker can't clear (#7671)
close #7534
1 parent 16e61be commit ba90876

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

components/date-picker/date-picker.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ export class NzDatePickerComponent implements OnInit, OnChanges, OnDestroy, Afte
801801
const newValue: CompatibleValue = this.datePickerService.makeValue(value);
802802
this.datePickerService.setValue(newValue);
803803
this.datePickerService.initialValue = newValue;
804+
this.cdr.detectChanges();
804805
}
805806

806807
renderClass(value: boolean): void {

components/date-picker/range-picker.component.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ describe('NzRangePickerComponent', () => {
161161
expect(debugElement.query(clearBtnSelector)).toBeFalsy();
162162
}));
163163

164+
it('should support clear input value when set default value', fakeAsync(() => {
165+
const clearBtnSelector = By.css(`.${PREFIX_CLASS}-clear`);
166+
fixtureInstance.modelValue = [new Date(), new Date()];
167+
fixtureInstance.nzAllowClear = true;
168+
tick();
169+
fixture.autoDetectChanges();
170+
171+
const leftInput = getPickerInput(fixture.debugElement);
172+
tick(500);
173+
debugElement.query(clearBtnSelector).nativeElement.click();
174+
expect(leftInput.attributes.getNamedItem('ng-reflect-model')?.value).toBeUndefined();
175+
}));
176+
164177
it('should support nzAutoFocus', fakeAsync(() => {
165178
fixtureInstance.nzAutoFocus = true;
166179
fixture.detectChanges();

0 commit comments

Comments
 (0)