KeyboardEvent.keyCode is deprecated
Closed this issue · 4 comments
jalezi commented
Description
In <Input/>
in keyDownHandler
we are using e.keyCode
which is, according to MDN, deprecated.
Solution
Use KeyboardEvent.code.
const KEYBOARD_CODES = {
ARROW_UP: "ArrowUp", // keyCode = 38
ARROW_DOWN: "ArrowDown", // keyCode = 40
ENTER: "Enter", // keyCode = 13
};
function keyDownHandler(e: any) {
if (e.code === KEYBOARD_CODES.ARROW_UP) {
setData(() => +dimensionBuffer + 1);
} else if (e.code === KEYBOARD_CODES.ARROW_DOWN) {
setData(() => +dimensionBuffer - 1);
} else if (e.code === KEYBOARD_CODES.ENTER) {
if (Number.isNaN(Number(dimensionBuffer))) {
setDimensionBuffer(data + "");
} else {
setData(() => +dimensionBuffer);
}
}
}
jalezi commented
@subhoghoshX you can assign me and I can fix also #37
subhoghoshX commented
Yeah I know it's deprecated, but one good thing about the web is that deprecated doesn't mean it'll soon be removed hehe.
You can work on it if you want. No need to create a separate object, just put the key name in the conditions.
jalezi commented
Do you care about nested if..else..if
? switch
is maybe more readable.
subhoghoshX commented
Yeah, feel free to use switch
.