R
fn

onStartTyping

v0.0.15testeddemo

Fires 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

ParameterTypeDescription
callback(event: KeyboardEvent) => voidInvoked with the originating `keydown` event
options?OnStartTypingOptionsOptions

Returns

VoidFunctionA function that detaches the `keydown` listener