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.

typescript

Interfaces consommées

IActiveProps
IActiveState

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

props
requis
IActiveProps & Record<string, any>
Component props. Reads `props[prop]` (default: `props.active`).
prop
string
'active'
The prop key to read for the active value. Use "modelValue" for components with a v-model binding.
name
string
getCurrentInstanceName()
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

vue

Forced active with style override

vue