Skip to content

Commit

Permalink
Fixed #5008 - InputNumber: Bug deprecated KeyCode Usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Mar 14, 2024
1 parent 2132672 commit ec04c03
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
20 changes: 10 additions & 10 deletions components/lib/inputmask/InputMask.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default {
return;
}
let k = event.which || event.keyCode,
let k = event.code,
pos,
begin,
end;
Expand All @@ -91,26 +91,26 @@ export default {
this.oldVal = this.$el.value;
//backspace, delete, and escape get special treatment
if (k === 8 || k === 46 || (iPhone && k === 127)) {
if (k === 'Backspace' || k === 'Delete' || (iPhone && k === 'Escape')) {
pos = this.caret();
begin = pos.begin;
end = pos.end;
if (end - begin === 0) {
begin = k !== 46 ? this.seekPrev(begin) : (end = this.seekNext(begin - 1));
end = k === 46 ? this.seekNext(end) : end;
begin = k !== 'Delete' ? this.seekPrev(begin) : (end = this.seekNext(begin - 1));
end = k === 'Delete' ? this.seekNext(end) : end;
}
this.clearBuffer(begin, end);
this.shiftL(begin, end - 1);
this.updateModel(event);
event.preventDefault();
} else if (k === 13) {
} else if (k === 'Enter') {
// enter
this.$el.blur();
this.updateModel(event);
} else if (k === 27) {
} else if (k === 'Escape') {
// escape
this.$el.value = this.focusText;
this.caret(0, this.checkVal());
Expand All @@ -125,17 +125,17 @@ export default {
return;
}
var k = event.which || event.keyCode,
var k = event.code,
pos = this.caret(),
p,
c,
next,
completed;
if (event.ctrlKey || event.altKey || event.metaKey || k < 32) {
if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey || event.key === 'CapsLock' || event.key === 'Escape' || event.key === 'Tab') {
//Ignore
return;
} else if (k && k !== 13) {
} else if (k && k !== 'Enter') {
if (pos.end - pos.begin !== 0) {
this.clearBuffer(pos.begin, pos.end);
this.shiftL(pos.begin, pos.end - 1);
Expand All @@ -144,7 +144,7 @@ export default {
p = this.seekNext(pos.begin - 1);
if (p < this.len) {
c = String.fromCharCode(k);
c = event.key;
if (this.tests[p].test(c)) {
this.shiftR(p);
Expand Down
33 changes: 16 additions & 17 deletions components/lib/inputnumber/InputNumber.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
:aria-invalid="invalid || undefined"
@input="onUserInput"
@keydown="onInputKeyDown"
@keypress="onInputKeyPress"
@paste="onPaste"
@click="onInputClick"
@focus="onInputFocus"
Expand Down Expand Up @@ -334,7 +333,7 @@ export default {
}
},
onUpButtonKeyDown(event) {
if (event.keyCode === 32 || event.keyCode === 13) {
if (event.code === 'Space' || event.code === 'Enter' || event.code === 'NumpadEnter') {
this.repeat(event, null, 1);
}
},
Expand All @@ -361,7 +360,7 @@ export default {
}
},
onDownButtonKeyDown(event) {
if (event.keyCode === 32 || event.keyCode === 13) {
if (event.code === 'Space' || event.code === 'Enter' || event.code === 'NumpadEnter') {
this.repeat(event, null, -1);
}
},
Expand Down Expand Up @@ -530,22 +529,22 @@ export default {
break;
default:
break;
}
},
onInputKeyPress(event) {
if (this.readonly) {
return;
}
if (this.readonly) {
return;
}
event.preventDefault();
let code = event.which || event.keyCode;
let char = String.fromCharCode(code);
const isDecimalSign = this.isDecimalSign(char);
const isMinusSign = this.isMinusSign(char);
event.preventDefault();
let char = event.key;
const isDecimalSign = this.isDecimalSign(char);
const isMinusSign = this.isMinusSign(char);
if ((48 <= code && code <= 57) || isMinusSign || isDecimalSign) {
this.insert(event, char, { isDecimalSign, isMinusSign });
if (((event.code.startsWith('Digit') || event.code.startsWith('Numpad')) && Number(char) >= 0 && Number(char) <= 9) || isMinusSign || isDecimalSign) {
console.log(event.code);
this.insert(event, char, { isDecimalSign, isMinusSign });
}
break;
}
},
onPaste(event) {
Expand Down
16 changes: 7 additions & 9 deletions components/lib/inputotp/InputOtp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,37 +129,35 @@ export default {
this.$emit('blur', event);
},
onKeyDown(event) {
const keyCode = event.keyCode;
switch (keyCode) {
case 37:
switch (event.code) {
case 'ArrowLeft':
this.moveToPrev(event);
event.preventDefault();
break;
case 38:
case 40:
case 'ArrowUp':
case 'ArrowDown':
event.preventDefault();
break;
case 8:
case 'Backspace':
if (event.target.value.length === 0) {
this.moveToPrev(event);
event.preventDefault();
}
break;
case 39:
case 'ArrowRight':
this.moveToNext(event);
event.preventDefault();
break;
default:
if ((this.integerOnly && !((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))) || (this.tokens.join('').length >= this.length && event.keyCode != 46)) {
if ((this.integerOnly && !((event.code.startsWith('Digit') || event.code.startsWith('Numpad')) && Number(event.code) >= 0 && Number(event.code) <= 9)) || (this.tokens.join('').length >= this.length && event.code !== 'Delete')) {
event.preventDefault();
}
Expand Down

0 comments on commit ec04c03

Please sign in to comment.