fn
onStartTyping
v0.0.15testeddemoFires the callback when the user starts typing on a non-editable element, ideal for auto-focusing a search box.
Examples
ts
const input = useTemplateRef('input');
onStartTyping(() => {
if (document.activeElement !== input.value)
input.value?.focus();
});ts
// stop listening manually
const stop = onStartTyping(() => openSearch());
stop();Demo
Loading demo…
Signature
ts
export function onStartTyping(
callback: (event: KeyboardEvent) => void,
options: OnStartTypingOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
callback | (event: KeyboardEvent) => void | Invoked with the originating `keydown` event |
options? | OnStartTypingOptions | Options |
Returns
VoidFunctionA function that detaches the `keydown` listener