e4ff408f23
Improve the accessibility of our modals (the color picker and the export dialog) Implement a focus trap so that tapping through the controls inside them don't escape to outer elements, it also allows to close the modals with the "Escape" key.
26 lines
553 B
TypeScript
26 lines
553 B
TypeScript
export const KEYS = {
|
|
ARROW_LEFT: "ArrowLeft",
|
|
ARROW_RIGHT: "ArrowRight",
|
|
ARROW_DOWN: "ArrowDown",
|
|
ARROW_UP: "ArrowUp",
|
|
ENTER: "Enter",
|
|
ESCAPE: "Escape",
|
|
DELETE: "Delete",
|
|
BACKSPACE: "Backspace",
|
|
get META() {
|
|
return /Mac|iPod|iPhone|iPad/.test(window.navigator.platform)
|
|
? "metaKey"
|
|
: "ctrlKey";
|
|
},
|
|
TAB: "Tab",
|
|
};
|
|
|
|
export function isArrowKey(keyCode: string) {
|
|
return (
|
|
keyCode === KEYS.ARROW_LEFT ||
|
|
keyCode === KEYS.ARROW_RIGHT ||
|
|
keyCode === KEYS.ARROW_DOWN ||
|
|
keyCode === KEYS.ARROW_UP
|
|
);
|
|
}
|