onStartTyping
Category Sensors
Fires when users start typing on non-editable elements.
Demo
Type anything
Usage
<script>
import { onStartTyping } from '@sv-use/core';
let input = $state();
onStartTyping(() => {
if (input !== document.activeElement) {
input?.focus();
}
});
</script>
<input bind:this={input} type="text" />
Type Definitions
import { type ConfigurableDocument } from '../__internal__/configurable.js';
import type { CleanupFunction } from '../__internal__/types.js';
interface OnStartTypingOptions extends ConfigurableDocument {
/**
* Whether to auto-cleanup the event listener or not.
*
* If set to `true`, it must run in the component initialization lifecycle.
* @default true
*/
autoCleanup?: boolean;
}
/**
* Fires when users start typing on non-editable elements.
* @param callback The callback for when users start typing on non-editable elements.
* @param options Additional options to customize the behavior.
* @see https://svelte-librarian.github.io/sv-use/docs/core/on-start-typing
*/
export declare function onStartTyping(callback: (event: KeyboardEvent) => void, options?: OnStartTypingOptions): CleanupFunction;
export {};