Skip to content

shortcut

Svelte action to add keyboard shortcuts.

See

shortcut

Type Aliases

KeyboardShortcut

type KeyboardShortcut: object;

Basic definition of a keyboard shortcut based on key and modifier keys.

Type declaration

alt?
optional alt: boolean;

Needs alt ?

ctrl?
optional ctrl: boolean;

Needs ctrl ?

key?
optional key: string;

Keyboard key.

shift?
optional shift: boolean;

Needs shift ?

Defined in

tmp/commons/src/lib/actions/shortcut.ts:14


ShortcutSettings<E>

type ShortcutSettings<E>: KeyboardShortcut & object;

Settings for a keyboard shortcut.

Type declaration

action()?
optional action: (node, e) => unknown;

Callback to be triggered when shortcut is activated.

Parameters

node: E

e: KeyboardEvent

Returns

unknown

endAction()?
optional endAction: (node, e) => void;

Callback to be triggered when key is released.

Parameters

node: E

e: KeyboardEvent

Returns

void

ignoreElements?
optional ignoreElements: string[];

Element types that prevents the shortcut from triggering.

Defaults to [‘INPUT’, ‘TEXTAREA’].

repeats?
optional repeats: boolean;

Should keep triggering if key is still pressed ?

Defaults to true.

shortcuts?
optional shortcuts: KeyboardShortcut[] | (e) => boolean | KeyboardShortcut;

List of shortcuts that trigger the action.

Can be a single shortcut or an array of shortcuts. If a function is provided, it should return a boolean indicating whether the shortcut is triggered based on the keyboard event.

Type Parameters

E extends Element

Defined in

tmp/commons/src/lib/actions/shortcut.ts:28

Functions

shortcut()

function shortcut<E>(node, params): ActionReturn<ShortcutSettings<E>>

Action to add a keyboard shortcut.

All keyboard listeners are attached to document.

Type Parameters

E extends Element

Parameters

node: E

The element the shortcut is bound to

params: ShortcutSettings<E>

Settings for the shortcut

Returns

ActionReturn<ShortcutSettings<E>>

svelte action to add a keyboard shortcut

Defined in

tmp/commons/src/lib/actions/shortcut.ts:173


shortcutToString()

function shortcutToString(param0): string

Converts a keyboard shortcut definition to a string.

Parameters

param0: KeyboardShortcut

Keyboard shortcut definition

Returns

string

Defined in

tmp/commons/src/lib/actions/shortcut.ts:156