subhoghoshX/laureate

KeyboardEvent.keyCode is deprecated

Closed this issue · 4 comments

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);
      }
    }
  }

@subhoghoshX you can assign me and I can fix also #37

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.

Do you care about nested if..else..if? switch is maybe more readable.

Yeah, feel free to use switch.