Skip to content

Commit 1ca1490

Browse files
authored
feat(module:time-picker): support null value in time-picker-panel (#1388)
1 parent 23cb39e commit 1ca1490

4 files changed

Lines changed: 51 additions & 38 deletions

File tree

PROGRESS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
| modal | 90% | 100% | 100% | wilsoncook ||
3939
| message | x | x | x | wilsoncook | - |
4040
| notification | x | x | x | wilsoncook | - |
41-
| datepicker | x | x | x | trotyl | - |
42-
| time-picker | x | x | x | trotyl | - |
41+
| datepicker | x | x | x | wilsoncook | - |
42+
| time-picker | | 100% | 100% | trotyl asnowwolf vthinkxie | |
4343
| calendar || 100% | 100% | trotyl ||
4444
| affix || 100% | 100% | cipchk ||
4545
| transfer || 100% | 100% | cipchk | x |
@@ -50,8 +50,8 @@
5050
| backtop || 100% | 100% | cipchk | x |
5151
| divider || 100% | 100% | cipchk | x |
5252
| treeselect | x | x | x | simplejason | - |
53-
| tree | x | x | x | simplejason | - |
54-
| cascader | x | x | x | fbchen | - |
53+
| tree | | 100% | 100% | simplejason | - |
54+
| cascader | | 100% | 100% | fbchen | - |
5555
| autocomplete || 100% | 100% | HsuanXyz | - |
5656
| mention || 100% | 100% | HsuanXyz | - |
5757

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ describe('time-picker-panel', () => {
5353
fixture.detectChanges();
5454
expect(testComponent.nzTimePickerPanelComponent.hourEnabled).toBe(true);
5555
expect(testComponent.nzTimePickerPanelComponent.minuteEnabled).toBe(true);
56-
expect(testComponent.nzTimePickerPanelComponent.secondEnabled).toBe(true);
57-
expect(testComponent.nzTimePickerPanelComponent.enabledColumns).toBe(3);
56+
expect(testComponent.nzTimePickerPanelComponent.secondEnabled).toBe(false);
57+
expect(testComponent.nzTimePickerPanelComponent.enabledColumns).toBe(2);
5858
});
5959
it('should default open value work', fakeAsync(() => {
6060
testComponent.nzTimePickerPanelComponent.opened = true;

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

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
3636
private sub: Subscription;
3737
private onChange: (value: Date) => void;
3838
private onTouch: () => void;
39-
private _format: string;
39+
private _format = 'HH:mm:ss';
4040
private _disabledHours: () => number[];
4141
private _disabledMinutes: (hour: number) => number[];
4242
private _disabledSeconds: (hour: number, minute: number) => number[];
4343
private _defaultOpenValue = new Date();
4444
private _opened = false;
45+
private _allowEmpty = true;
4546
time = new TimeHolder();
4647
hourEnabled = true;
4748
minuteEnabled = true;
@@ -58,9 +59,19 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
5859
@Input() nzHideDisabledOptions = false;
5960
@Input() nzClearText: string;
6061
@Input() nzPlaceHolder: string;
61-
@Input() nzAllowEmpty = true;
6262
@Output() timeClear = new EventEmitter<void>();
6363

64+
@Input()
65+
set nzAllowEmpty(value: boolean) {
66+
if (isNotNil(value)) {
67+
this._allowEmpty = value;
68+
}
69+
}
70+
71+
get nzAllowEmpty(): boolean {
72+
return this._allowEmpty;
73+
}
74+
6475
@Input()
6576
set opened(value: boolean) {
6677
this._opened = value;
@@ -98,8 +109,8 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
98109

99110
@Input()
100111
set nzDisabledMinutes(value: (hour: number) => number[]) {
101-
this._disabledMinutes = value;
102-
if (this._disabledMinutes) {
112+
if (isNotNil(value)) {
113+
this._disabledMinutes = value;
103114
this.buildMinutes();
104115
}
105116
}
@@ -110,8 +121,8 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
110121

111122
@Input()
112123
set nzDisabledSeconds(value: (hour: number, minute: number) => number[]) {
113-
this._disabledSeconds = value;
114-
if (this._disabledSeconds) {
124+
if (isNotNil(value)) {
125+
this._disabledSeconds = value;
115126
this.buildSeconds();
116127
}
117128
}
@@ -122,28 +133,21 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
122133

123134
@Input()
124135
set format(value: string) {
125-
if (value !== this._format) {
136+
if (isNotNil(value)) {
126137
this._format = value;
127-
if (isNotNil(value)) {
128-
this.enabledColumns = 0;
129-
const charSet = new Set(value);
130-
this.hourEnabled = charSet.has('H') || charSet.has('h');
131-
this.minuteEnabled = charSet.has('m');
132-
this.secondEnabled = charSet.has('s');
133-
if (this.hourEnabled) {
134-
this.enabledColumns++;
135-
}
136-
if (this.minuteEnabled) {
137-
this.enabledColumns++;
138-
}
139-
if (this.secondEnabled) {
140-
this.enabledColumns++;
141-
}
142-
} else {
143-
this.hourEnabled = true;
144-
this.minuteEnabled = true;
145-
this.secondEnabled = true;
146-
this.enabledColumns = 3;
138+
this.enabledColumns = 0;
139+
const charSet = new Set(value);
140+
this.hourEnabled = charSet.has('H') || charSet.has('h');
141+
this.minuteEnabled = charSet.has('m');
142+
this.secondEnabled = charSet.has('s');
143+
if (this.hourEnabled) {
144+
this.enabledColumns++;
145+
}
146+
if (this.minuteEnabled) {
147+
this.enabledColumns++;
148+
}
149+
if (this.secondEnabled) {
150+
this.enabledColumns++;
147151
}
148152
}
149153
}
@@ -154,7 +158,7 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
154158

155159
@Input()
156160
set nzHourStep(value: number) {
157-
if (this._nzHourStep !== value) {
161+
if (isNotNil(value)) {
158162
this._nzHourStep = value;
159163
this.buildHours();
160164
}
@@ -166,7 +170,7 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
166170

167171
@Input()
168172
set nzMinuteStep(value: number) {
169-
if (this._nzMinuteStep !== value) {
173+
if (isNotNil(value)) {
170174
this._nzMinuteStep = value;
171175
this.buildMinutes();
172176
}
@@ -178,7 +182,7 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
178182

179183
@Input()
180184
set nzSecondStep(value: number) {
181-
if (this._nzSecondStep !== value) {
185+
if (isNotNil(value)) {
182186
this._nzSecondStep = value;
183187
this.buildSeconds();
184188
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
6868
private _autoFocus = false;
6969
private _onChange: (value: Date) => void;
7070
private _onTouched: () => void;
71+
private _hideDisabledOptions = false;
7172
isInit = false;
7273
origin: CdkOverlayOrigin;
7374
overlayPositions: ConnectionPositionPair[] = [ {
@@ -87,7 +88,6 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
8788
@Input() nzPopupClassName = '';
8889
@Input() nzPlaceHolder = '';
8990
@Input() nzAddOn: TemplateRef<void>;
90-
@Input() nzHideDisabledOptions = false;
9191
@Input() nzDefaultOpenValue = new Date();
9292
@Input() nzDisabledHours: () => number[];
9393
@Input() nzDisabledMinutes: (hour: number) => number[];
@@ -96,6 +96,15 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
9696
@Input() nzOpen = false;
9797
@Output() nzOpenChange = new EventEmitter<boolean>();
9898

99+
@Input()
100+
set nzHideDisabledOptions(value: boolean) {
101+
this._hideDisabledOptions = toBoolean(value);
102+
}
103+
104+
get nzHideDisabledOptions(): boolean {
105+
return this._hideDisabledOptions;
106+
}
107+
99108
@Input()
100109
set nzAllowEmpty(value: boolean) {
101110
this._allowEmpty = toBoolean(value);
@@ -205,7 +214,7 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
205214
}
206215

207216
writeValue(time: Date | null): void {
208-
this.value = time;
217+
this._value = time;
209218
}
210219

211220
registerOnChange(fn: (time: Date) => void): void {

0 commit comments

Comments
 (0)