Skip to content

Commit 96a93e0

Browse files
committed
Fixed #44 - Delete button is not triggering on (codechanged)
1 parent bf09c7d commit 96a93e0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

angular-code-input/src/lib/code-input.component.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,10 @@ export class CodeInputComponent implements AfterViewInit, OnInit, OnChanges, OnD
254254
const isTargetEmpty = this.isEmpty(target.value);
255255
const prev = i - 1;
256256

257-
// processing only backspace events
257+
// processing only the backspace and delete key events
258258
const isBackspaceKey = await this.isBackspaceKey(e);
259-
if (!isBackspaceKey) {
259+
const isDeleteKey = this.isDeleteKey(e);
260+
if (!isBackspaceKey && !isDeleteKey) {
260261
return;
261262
}
262263

@@ -267,7 +268,8 @@ export class CodeInputComponent implements AfterViewInit, OnInit, OnChanges, OnD
267268
this.emitChanges();
268269
}
269270

270-
if (prev < 0) {
271+
// preventing to focusing on the previous field if it does not exist or the delete key has been pressed
272+
if (prev < 0 || isDeleteKey) {
271273
return;
272274
}
273275

@@ -401,6 +403,10 @@ export class CodeInputComponent implements AfterViewInit, OnInit, OnChanges, OnD
401403
});
402404
}
403405

406+
private isDeleteKey(e: any): boolean {
407+
return (e.key && e.key.toLowerCase() === 'delete') || (e.keyCode && e.keyCode === 46);
408+
}
409+
404410
private setInputValue(input: HTMLInputElement, value: any): void {
405411
const isEmpty = this.isEmpty(value);
406412
const valueClassCSS = 'has-value';

0 commit comments

Comments
 (0)