svelte-event
Version:
svelte-event provides a set of wrapper functions for adding modifiers to event handlers and a versatile `event` action for comprehensive event listener management in Svelte.
25 lines (24 loc) • 1.13 kB
TypeScript
type KeyboardEventHandler<T extends KeyboardEvent = KeyboardEvent> = (event: T) => void;
/**
* Creates a modifier that only triggers the handler if a specific key is pressed.
*/
export declare function key<T extends KeyboardEvent, U extends HTMLElement>(
/** The original event handler. */
handler: KeyboardEventHandler<T>,
/** The key to check for (e.g., 'Enter', 'Shift', 'a'). Must be a valid KeyboardEvent.key value.
* @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values
*/
key: string, options?: {
/** The modifiers that need to be pressed for the handler to be triggered. */
/** Whether the Alt key needs to be pressed. */
altKey?: boolean;
/** Whether the Ctrl key needs to be pressed. */
ctrlKey?: boolean;
/** Whether the Meta key (Command key on Mac, Windows key on Windows) needs to be pressed. */
metaKey?: boolean;
/** Whether the Shift key needs to be pressed. */
shiftKey?: boolean;
/** Whether the exact modifiers need to be pressed (i.e. no other modifiers can be pressed). */
exact?: boolean;
}): KeyboardEventHandler<T>;
export {};