Skip to content

Commit

Permalink
fix(module:date-picker): keep the time value while clicking date (#3911)
Browse files Browse the repository at this point in the history
* chore(module:date-picker): keep the time value while clicking date

* chore: delete jugdement
  • Loading branch information
wenqi73 authored Aug 8, 2019
1 parent 045eef4 commit 9499aec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/calendar/date-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ export class DateTableComponent implements OnInit, OnChanges {
}

private changeValueFromInside(value: CandyDate): void {
if (this.value !== value) {
this.valueChange.emit(value);
}
// Only change date not change time
const newValue = this.value
.setYear(value.getYear())
.setMonth(value.getMonth())
.setDate(value.getDate());
this.valueChange.emit(newValue);
}

private makeHeadWeekDays(): WeekDayLabel[] {
Expand Down
14 changes: 14 additions & 0 deletions components/date-picker/nz-date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,20 @@ describe('NzDatePickerComponent', () => {
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('2018-11-11 00:22:33');
}));

it('should not reset time', fakeAsync(() => {
fixtureInstance.nzValue = new Date('2019-08-02 13:03:33');
fixtureInstance.nzShowTime = true;
fixture.detectChanges();
openPickerByClickTrigger();

dispatchMouseEvent(queryFromOverlay('.ant-calendar-cell > .ant-calendar-date'), 'click');

fixture.detectChanges();
flush();
fixture.detectChanges();
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toBe('2019-07-29 13:03:33');
}));

it('should support nzShowTime.nzFormat', fakeAsync(() => {
fixtureInstance.nzShowTime = { nzFormat: 'HH:mm' };
fixture.detectChanges();
Expand Down

0 comments on commit 9499aec

Please sign in to comment.