UNPKG

@hitachivantara/uikit-react-core

Version:

Core React components for the NEXT Design System.

34 lines (33 loc) 719 B
const keyboardCodes = { Backspace: "Backspace", Tab: "Tab", Enter: "Enter", Shift: "ShiftLeft", Ctrl: "ControlLeft", Alt: "AltLeft", Delete: "Delete", Esc: "Escape", ArrowLeft: "ArrowLeft", ArrowUp: "ArrowUp", ArrowRight: "ArrowRight", ArrowDown: "ArrowDown", Space: "Space", PageUp: "PageUp", PageDown: "PageDown", Home: "Home", End: "End" }; const isKey = (event, keyCode) => { return event?.code === keyCode || event?.code === keyboardCodes[keyCode]; }; const isOneOfKeys = (event, keys) => { return keys.some((key) => isKey(event, key)); }; function isDeleteKey(event) { return isOneOfKeys(event, ["Backspace", "Delete"]); } export { isDeleteKey, isKey, isOneOfKeys };