Switch
Form & Input
stable
Toggle switch input that wraps a hidden checkbox for binary on/off state, with optional inset style, loading states and track slot customization.
API
Props
Toutes les props acceptées par ce composant, avec leur type, valeur par défaut et description.
- indeterminatebooleanfalse
- Puts the switch into a three-state (mixed) visual state. The indeterminate state clears on the next toggle.
- insetbooleanfalse
- Material inset variant — the thumb overflows the track edges and expands when active.
- idstring
- flatbooleanfalse
- Removes the default thumb elevation, producing a flat appearance.
- classstring | Array<string> | object
- stylestring | Array<string> | object | StyleValue
- tagstring'div'
- HTML element rendered at the root.
- paddingboolean | number | string
- paddingTopboolean | number | string
- paddingLeftboolean | number | string
- paddingBottomboolean | number | string
- paddingRightboolean | number | string
- paddingBlockboolean | number | string
- paddingInlineboolean | number | string
- paddingInlineStartboolean | number | string
- paddingInlineEndboolean | number | string
- paddingBlockStartboolean | number | string
- paddingBlockEndboolean | number | string
- marginboolean | number | string
- marginTopboolean | number | string
- marginLeftboolean | number | string
- marginBottomboolean | number | string
- marginRightboolean | number | string
- marginBlockboolean | number | string
- marginInlineboolean | number | string
- marginInlineStartboolean | number | string
- marginInlineEndboolean | number | string
- marginBlockStartboolean | number | string
- marginBlockEndboolean | number | string
- borderboolean | number | string | TDirectionBoth | Array<TDirectionBoth>
- borderTopboolean | number | string
- borderLeftboolean | number | string
- borderBottomboolean | number | string
- borderRightboolean | number | string
- borderBlockboolean | number | string
- borderInlineboolean | number | string
- borderInlineStartboolean | number | string
- borderInlineEndboolean | number | string
- borderBlockStartboolean | number | string
- borderBlockEndboolean | number | string
- borderColorstring
- borderStylestring
- borderTopColorTColor
- borderRightColorTColor
- borderBottomColorTColor
- borderLeftColorTColor
- borderInlineStartColorTColor
- borderInlineEndColorTColor
- borderBlockStartColorTColor
- borderBlockEndColorTColor
- roundedboolean | number | string | TRounded | null | undefined
- roundedTopRightboolean | number | string
- roundedTopLeftboolean | number | string
- roundedBottomLeftboolean | number | string
- roundedBottomRightboolean | number | string
- roundedStartStartboolean | number | string
- roundedStartEndboolean | number | string
- roundedEndStartboolean | number | string
- roundedEndEndboolean | number | string
- centerAffixboolean
- hideDetailsboolean | stringfalse
- Hides the validation messages area below the control.
- hideSpinButtonsboolean
- hintstring
- persistentHintboolean
- messagesArray<string> | string
- densityTDensity'default'
- Adjusts vertical padding density of the input row.
- colorTColor
- Active-state color applied to the thumb and track via intent tokens.
- bgColorTColor
- elevationTElevation
- heightnumber | string
- maxHeightnumber | string
- maxWidthnumber | string
- minHeightnumber | string
- minWidthnumber | string
- widthnumber | string
- directionTDirection
- disabledbooleanfalse
- Disables the switch — prevents interaction and applies muted styling.
- errorstring | boolean
- errorMessagesArray<string> | string
- maxErrorsnumber | string
- namestring
- readonlybooleanfalse
- Keeps the visual appearance interactive but blocks state changes.
- rulesArray<any>
- modelValueany
- Bound value of the switch. Bind with v-model.
- validateOnTValidateOn
- validationValueany
- focusedboolean
- appendAvatarstring
- appendIconTIcon
- prependAvatarstring
- prependIconTIcon
- prependAriaLabelstring
- appendAriaLabelstring
- sizeTSize | number
- fontSizeTFontSize
- fontWeightTFontWeight
- lineHeightTLineHeight
- labelstring
- Visible text label associated with the switch.
- trueValueany
- falseValueany
- valueany
- requiredboolean
- typestring
- valueComparator(a: any, b: any) => boolean
- falseIconTIcon
- trueIconTIcon
- multipleboolean
- inlineboolean
- hoverboolean | IStateEffectConfig
- hoverClassstring
- rippleboolean | { class: string }
- loadingTControlLoadingValuefalse
- Loading state. 'circular' shows a spinner in the thumb; 'line' overlays the track; 'skeleton' replaces the entire switch.
- loadingTextstring
- activeboolean | IStateEffectConfig
- activeClassstring
API
Slots
Emplacements de contenu exposés par ce composant.
- #track.true
- Content rendered on the ON (left) half of the track, e.g. a checkmark icon.
- #default
- Label content rendered beside the track.
- #track.false
- Content rendered on the OFF (right) half of the track, e.g. an X icon.
- #loader
- Custom spinner rendered inside the thumb while loading.
API
Emits
Événements émis par ce composant.
- @update:modelValueany
- Fired when the switch is toggled. Bind with v-model.
- @update:focusedany
- @update:indeterminateboolean
- Fired when the indeterminate state is cleared on toggle.
- @focusFocusEvent
- Fired when the hidden input receives focus.
- @click:labelMouseEvent
- Fired when the user clicks the associated label element.
- @blurFocusEvent
- Fired when the hidden input loses focus.
Interactif
Playground
Modifiez les props en direct et observez le composant se mettre à jour. Le snippet de code généré suit vos changements.
Rendu de l’aperçu en cours…
Usage
Exemples
Extraits de code prêts à coller dans vos templates.
Basic switch
Inset & color
Custom track content
Écosystème
Famille
Composants du même dossier qui partagent les conventions et se composent souvent ensemble.