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
Signature TypeScript complète extraite du fichier du composable.
Interfaces consommées
IFocusProps
IFocusEmits
API
Paramètres
Paramètres d'entrée acceptés par ce composable.
- propsrequisIFocusProps
- Component props containing the optional `focused` boolean. Drives the two-way binding via useVModel.
- namestringgetCurrentInstanceName()
- Component name used to generate the scoped focus class (e.g. "origam-text-field--focused"). Defaults to the current Vue instance name.
API
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- 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
Exemples
Extraits de code prêts à coller.
Input field with focus styling
Programmatic focus via v-model:focused