Event Helpers¶
A set of helper functions that assist in handling events.
Installation¶
Terminal
pnpm add @mvps-genesis/event-helpers
Example Usage¶
.js¶
import {
hasKeyboardModifier,
isKeyboardEvent,
isMouseEvent
} from '@mvps-genesis/event-helpers';
// Check if a keyboard event object has modifier keys pressed
element.addEventListener('keydown', (e) => {
// User presses `ALT+A`
hasKeyboardModifier(e); // true
// Test for ONLY a specific modifier, in this case only `alt`.
// User presses `ALT+SHIFT+A`
hasKeyboardModifier(e, { // false
shift: false,
meta: false,
ctrl: false
});
// User presses `ALT+A`
hasKeyboardModifier(e, { // true
shift: false,
meta: false,
ctrl: false
});
});
// Check if event name/type is a keyboard event
isKeyboardEvent('mouseover'); // false
isKeyboardEvent('keydown'); // true
// Check if event name/type is a mouse event
isMouseEvent('mouseover'); // true
isMouseEvent('keydown'); // false