Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/onStartTyping.md
1---2category: Sensors3---45# onStartTyping67Fires when users start typing on non-editable elements. Useful for auto-focusing an input field when the user starts typing anywhere on the page.89## Usage1011```vue12<script setup lang="ts">13import { onStartTyping } from '@vueuse/core'14import { useTemplateRef } from 'vue'1516const input = useTemplateRef('input')1718onStartTyping(() => {19if (!input.value.active)20input.value.focus()21})22</script>2324<template>25<input ref="input" type="text" placeholder="Start typing to focus">26</template>27```2829## How It Works3031The callback only fires when:3233- No editable element (`<input>`, `<textarea>`, or `contenteditable`) is focused34- The pressed key is alphanumeric (A-Z, 0-9)35- No modifier keys (Ctrl, Alt, Meta) are held3637This allows users to start typing anywhere on the page without accidentally triggering the callback when using keyboard shortcuts or interacting with form fields.3839## Type Declarations4041```ts42/**43* Fires when users start typing on non-editable elements.44*45* @see https://vueuse.org/onStartTyping46* @param callback47* @param options48*/49export declare function onStartTyping(50callback: (event: KeyboardEvent) => void,51options?: ConfigurableDocument,52): void53```54