@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
56 lines (55 loc) • 898 B
JavaScript
/**
* Standardize key property of keyboard event (mostly for ie11)
*/
export function getKey(key, dir) {
const lookup = {
Up: "ArrowUp",
Down: "ArrowDown",
Left: "ArrowLeft",
Right: "ArrowRight",
Spacebar: " ",
Esc: "Escape"
};
const adjustedKey = lookup[key] || key;
const isRTL = dir === "rtl";
if (isRTL && adjustedKey === "ArrowLeft") {
return "ArrowRight";
}
if (isRTL && adjustedKey === "ArrowRight") {
return "ArrowLeft";
}
return adjustedKey;
}
export function isActivationKey(key) {
key = getKey(key);
return key === "Enter" || key === " ";
}
export const numberKeys = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
export const letterKeys = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z"
];