useFocus

Commons
stable

Tracks the focus state of a form control and emits the v-model:focused update. Returns focus/blur event handlers and a component-scoped CSS class that is active while the element is focused.

API

Signature

Full TypeScript signature sourced from the composable file.

typescript

Consumed interfaces

IFocusProps
IFocusEmits

API

Parameters

Input parameters accepted by this composable.

props
required
IFocusProps
Component props containing the optional `focused` boolean. Drives the two-way binding via useVModel.
name
string
getCurrentInstanceName()
Component name used to generate the scoped focus class (e.g. "origam-text-field--focused"). Defaults to the current Vue instance name.

API

Return values

Properties and methods exposed by the composable return object.

isFocused
Reactive two-way ref for the focused state. Writing true/false programmatically also fires the update:focused emit.
focusClasses
Class map containing `{name}--focused: isFocused.value`. Bind on the component root to reflect focus state via CSS.
onFocus
Handler to attach to the native focus event. Sets isFocused to true.
onBlur
Handler to attach to the native blur event. Sets isFocused to false.

Usage

Examples

Ready-to-paste usage snippets.

Input field with focus styling

vue

Programmatic focus via v-model:focused

vue