Skip to content

Commit

Permalink
fix(module:date-picker): select date but nzDefaultOpenValue not work (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wenqi73 authored and Yadong Xie committed Dec 2, 2019
1 parent d96ebe0 commit 2397819
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
4 changes: 1 addition & 3 deletions components/core/time/candy-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ export class CandyDate implements IndexableObject {
}

setHms(hour: number, minute: number, second: number): CandyDate {
const date = new Date(this.nativeDate);
date.setHours(hour, minute, second);
return new CandyDate(date);
return new CandyDate(this.nativeDate.setHours(hour, minute, second));
}

setYear(year: number): CandyDate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
[showWeek]="showWeek"
[value]="value"
(valueChange)="onSelectDate($event)"
showWeekNumber="false"
[disabledDate]="disabledDate"
[dateCellRender]="dateRender"
[selectedValue]="selectedValue"
Expand Down
12 changes: 9 additions & 3 deletions components/date-picker/lib/popups/inner-popup.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {

import { CandyDate, FunctionProp } from 'ng-zorro-antd/core';
import { NzCalendarI18nInterface } from 'ng-zorro-antd/i18n';
import { DisabledDateFn, PanelMode } from '../../standard-types';
import { DisabledDateFn, PanelMode, SupportTimeOptions } from '../../standard-types';

@Component({
encapsulation: ViewEncapsulation.None,
Expand All @@ -33,8 +33,7 @@ export class InnerPopupComponent {

@Input() locale: NzCalendarI18nInterface;
@Input() showTimePicker: boolean;
// tslint:disable-next-line:no-any
@Input() timeOptions: any;
@Input() timeOptions: SupportTimeOptions;
@Input() enablePrev: boolean;
@Input() enableNext: boolean;
@Input() disabledDate: DisabledDateFn;
Expand All @@ -61,6 +60,13 @@ export class InnerPopupComponent {
// The value real changed to outside
onSelectDate(date: CandyDate | Date): void {
const value = date instanceof CandyDate ? date : new CandyDate(date);
const timeValue = this.timeOptions && this.timeOptions.nzDefaultOpenValue;

// Display timeValue when value is null
if (!this.value && timeValue) {
value.setHms(timeValue.getHours(), timeValue.getMinutes(), timeValue.getSeconds());
}

this.selectDate.emit(value);
}
}
8 changes: 7 additions & 1 deletion components/date-picker/nz-date-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,12 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
openPickerByClickTrigger();

dispatchMouseEvent(getFirstCell(), 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect((queryFromOverlay('input.ant-calendar-input') as HTMLInputElement).value).toContain('00:01:02');

// Open time picker panel
dispatchMouseEvent(queryFromOverlay('.ant-calendar-time-picker-btn'), 'click');
fixture.detectChanges();
Expand All @@ -668,7 +674,7 @@ describe('NzDatePickerComponent', () => {
fixture.detectChanges();
openPickerByClickTrigger();

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

fixture.detectChanges();
flush();
Expand Down
1 change: 1 addition & 0 deletions components/date-picker/standard-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface SupportTimeOptions {
nzHideDisabledOptions?: boolean;
nzDefaultOpenValue?: Date;
nzAddOn?: TemplateRef<void>;
nzUse12Hours?: boolean;
}

export interface PresetRanges {
Expand Down

0 comments on commit 2397819

Please sign in to comment.