Skip to content

Commit da97b02

Browse files
authored
feat(module:input): input-otp supports keyboard control positioning (#9268)
1 parent f94cb31 commit da97b02

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎components/input/input-otp.component.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
44
*/
55

6-
import { BACKSPACE } from '@angular/cdk/keycodes';
6+
import { BACKSPACE, LEFT_ARROW, RIGHT_ARROW } from '@angular/cdk/keycodes';
77
import {
88
booleanAttribute,
99
ChangeDetectionStrategy,
@@ -134,6 +134,12 @@ export class NzInputOtpComponent implements ControlValueAccessor, OnChanges {
134134
}
135135

136136
this.emitValue();
137+
} else if (event.keyCode === LEFT_ARROW) {
138+
event.preventDefault();
139+
this.selectInputBox(index - 1);
140+
} else if (event.keyCode === RIGHT_ARROW) {
141+
event.preventDefault();
142+
this.selectInputBox(index + 1);
137143
}
138144
}
139145

@@ -225,6 +231,7 @@ export class NzInputOtpComponent implements ControlValueAccessor, OnChanges {
225231

226232
private selectInputBox(index: number): void {
227233
const otpInputArray = this.otpInputs.toArray();
234+
if (index <= 0) index = 0;
228235
if (index >= otpInputArray.length) index = otpInputArray.length - 1;
229236

230237
otpInputArray[index].nativeElement.select();

0 commit comments

Comments
 (0)