fn

onStartTyping

v0.0.14testeddemo

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

OnStartTypingReturnA function that detaches the keydown listener