useActive
Commons
stable
Tracks the active (pressed / selected) state of a host element with full v-model integration. Accepts boolean, forced-on (true) and IActiveState config objects with style overrides. The `prop` argument lets callers bind non-`active` keys (e.g. `modelValue`).
API
Signature
Signature TypeScript complète extraite du fichier du composable.
Interfaces consommées
IActiveProps
IActiveState
API
Paramètres
Paramètres d'entrée acceptés par ce composable.
- propsrequisIActiveProps & Record<string, any>
- Component props. Reads `props[prop]` (default: `props.active`).
- propstring'active'
- The prop key to read for the active value. Use "modelValue" for components with a v-model binding.
- namestringgetCurrentInstanceName()
- Component name prefix for the `{name}--active` class.
API
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- isActive
- Derived active state. True when forced, when the boolean prop is true, or when the internal toggle is on.
- activeState
- The IActiveState config object when the consumer passed one, undefined otherwise. Consumed by useStateEffect.
- activeClasses
- Includes `{name}--active` when isActive is true, plus the optional `activeClass` prop value.
- onActive
- Toggle function. Flips the v-model for boolean props, or the internal toggle for IActiveState config objects.
Usage
Exemples
Extraits de code prêts à coller.
Toggle button with v-model
Forced active with style override