arrowtab
Version:
Use arrow keys to "tab" between focusable elements
24 lines • 909 B
JavaScript
const inputTypesWithAllowedNativeArrowKeyPresses = {
text: ['ArrowLeft', 'ArrowRight'],
date: ['ArrowLeft', 'ArrowRight'],
time: ['ArrowLeft', 'ArrowRight'],
datetime: ['ArrowLeft', 'ArrowRight'],
'datetime-local': ['ArrowLeft', 'ArrowRight'],
month: ['ArrowLeft', 'ArrowRight'],
week: ['ArrowLeft', 'ArrowRight'],
number: ['ArrowLeft', 'ArrowRight'],
};
export const preventNativeArrowKeyPresses = ({ event, activeElement, }) => {
if (activeElement instanceof HTMLInputElement) {
const inputType = activeElement.type;
const allowedKeys = inputTypesWithAllowedNativeArrowKeyPresses[inputType];
if (allowedKeys && allowedKeys.includes(event.key)) {
return;
}
}
if (activeElement instanceof HTMLTextAreaElement) {
return;
}
event.preventDefault();
};
//# sourceMappingURL=preventNativeArrowKeyPresses.js.map