Skip to content

Commit 2dcefe2

Browse files
feat(module:time-picker): support input readonly (#7660)
1 parent 2d2fe33 commit 2dcefe2

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

components/time-picker/doc/index.en-US.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { NzTimePickerModule } from 'ng-zorro-antd/time-picker';
4747
| `[nzSize]` | width of time picker box | `'large' \| 'small' \| 'default'` | `'default'` |
4848
| `[nzStatus]` | Set validation status | `'error' \| 'warning'` | - |
4949
| `[nzBorderless]` | remove the border | `boolean` | `false` | - |
50+
| `[nzInputReadOnly]` | set the readonly attribute of the input tag (avoids virtual keyboard on touch devices) | `boolean` | `false` | - |
5051
| `[nzOpen]` | whether to popup panel, double binding | `boolean` | `false` |
5152
| `[nzPlaceHolder]` | display when there's no value | `string` | `"Select a time"` |
5253
| `[nzPopupClassName]` | className of panel | `string` | `''` ||

components/time-picker/doc/index.zh-CN.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { NzTimePickerModule } from 'ng-zorro-antd/time-picker';
4848
| `[nzSize]` | 时间选择框大小 | `'large'\|'small'\|'default'` | `'default'` |
4949
| `[nzStatus]` | 设置校验状态 | `'error' \| 'warning'` | - |
5050
| `[nzBorderless]` | 移除边框 | `boolean` | `false` | - |
51+
| `[nzInputReadOnly]` | 为 input 标签设置只读属性(避免在移动设备上触发小键盘) | `boolean` | `false` | - |
5152
| `[nzOpen]` | 面板是否打开,可双向绑定 | `boolean` | `false` |
5253
| `[nzPlaceHolder]` | 没有值的时候显示的内容 | `string` | `"请选择时间"` |
5354
| `[nzPopupClassName]` | 弹出层类名 | `string` | `''` ||

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

+11
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ describe('time-picker', () => {
9696
fixture.detectChanges();
9797
expect(timeElement.nativeElement.querySelector('input').attributes.getNamedItem('disabled')).toBeNull();
9898
});
99+
it('should readOnly work', () => {
100+
testComponent.nzInputReadOnly = true;
101+
fixture.detectChanges();
102+
expect(getPickerInput(fixture.debugElement).readOnly).toBeTruthy();
103+
104+
testComponent.nzInputReadOnly = false;
105+
fixture.detectChanges();
106+
expect(getPickerInput(fixture.debugElement).readOnly).not.toBeTruthy();
107+
});
99108
it('should open and close work', () => {
100109
testComponent.open = true;
101110
fixture.detectChanges();
@@ -397,6 +406,7 @@ describe('time-picker', () => {
397406
[(nzOpen)]="open"
398407
(nzOpenChange)="openChange($event)"
399408
[nzDisabled]="disabled"
409+
[nzInputReadOnly]="nzInputReadOnly"
400410
[nzUse12Hours]="use12Hours"
401411
[nzSuffixIcon]="nzSuffixIcon"
402412
[nzBackdrop]="nzBackdrop"
@@ -411,6 +421,7 @@ export class NzTestTimePickerComponent {
411421
autoFocus = false;
412422
date: Date | string = new Date();
413423
disabled = false;
424+
nzInputReadOnly = false;
414425
use12Hours = false;
415426
nzSuffixIcon?: string;
416427
nzBackdrop = false;

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

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'timePicker';
5757
[placeholder]="nzPlaceHolder || (i18nPlaceHolder$ | async)"
5858
[(ngModel)]="inputValue"
5959
[disabled]="nzDisabled"
60+
[readOnly]="nzInputReadOnly"
6061
(focus)="onFocus(true)"
6162
(blur)="onFocus(false)"
6263
(keyup.enter)="onKeyupEnter()"
@@ -143,6 +144,7 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
143144
static ngAcceptInputType_nzDisabled: BooleanInput;
144145
static ngAcceptInputType_nzAutoFocus: BooleanInput;
145146
static ngAcceptInputType_nzBorderless: BooleanInput;
147+
static ngAcceptInputType_nzInputReadOnly: BooleanInput;
146148

147149
private _onChange?: (value: Date | null) => void;
148150
private _onTouched?: () => void;
@@ -222,6 +224,7 @@ export class NzTimePickerComponent implements ControlValueAccessor, OnInit, Afte
222224
@Input() @InputBoolean() nzAutoFocus = false;
223225
@Input() @WithConfig() nzBackdrop = false;
224226
@Input() @InputBoolean() nzBorderless: boolean = false;
227+
@Input() @InputBoolean() nzInputReadOnly: boolean = false;
225228

226229
emitValue(value: Date | null): void {
227230
this.setValue(value, true);

0 commit comments

Comments
 (0)