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.

indeterminate
boolean
false
Puts the switch into a three-state (mixed) visual state. The indeterminate state clears on the next toggle.
inset
boolean
false
Material inset variant — the thumb overflows the track edges and expands when active.
id
string
flat
boolean
false
Removes the default thumb elevation, producing a flat appearance.
class
string | Array<string> | object
style
string | Array<string> | object | StyleValue
tag
string
'div'
HTML element rendered at the root.
padding
boolean | number | string
paddingTop
boolean | number | string
paddingLeft
boolean | number | string
paddingBottom
boolean | number | string
paddingRight
boolean | number | string
paddingBlock
boolean | number | string
paddingInline
boolean | number | string
paddingInlineStart
boolean | number | string
paddingInlineEnd
boolean | number | string
paddingBlockStart
boolean | number | string
paddingBlockEnd
boolean | number | string
margin
boolean | number | string
marginTop
boolean | number | string
marginLeft
boolean | number | string
marginBottom
boolean | number | string
marginRight
boolean | number | string
marginBlock
boolean | number | string
marginInline
boolean | number | string
marginInlineStart
boolean | number | string
marginInlineEnd
boolean | number | string
marginBlockStart
boolean | number | string
marginBlockEnd
boolean | number | string
border
boolean | number | string | TDirectionBoth | Array<TDirectionBoth>
borderTop
boolean | number | string
borderLeft
boolean | number | string
borderBottom
boolean | number | string
borderRight
boolean | number | string
borderBlock
boolean | number | string
borderInline
boolean | number | string
borderInlineStart
boolean | number | string
borderInlineEnd
boolean | number | string
borderBlockStart
boolean | number | string
borderBlockEnd
boolean | number | string
borderColor
string
borderStyle
string
borderTopColor
TColor
borderRightColor
TColor
borderBottomColor
TColor
borderLeftColor
TColor
borderInlineStartColor
TColor
borderInlineEndColor
TColor
borderBlockStartColor
TColor
borderBlockEndColor
TColor
rounded
boolean | number | string | TRounded | null | undefined
roundedTopRight
boolean | number | string
roundedTopLeft
boolean | number | string
roundedBottomLeft
boolean | number | string
roundedBottomRight
boolean | number | string
roundedStartStart
boolean | number | string
roundedStartEnd
boolean | number | string
roundedEndStart
boolean | number | string
roundedEndEnd
boolean | number | string
centerAffix
boolean
hideDetails
boolean | string
false
Hides the validation messages area below the control.
hideSpinButtons
boolean
hint
string
persistentHint
boolean
messages
Array<string> | string
density
TDensity
'default'
Adjusts vertical padding density of the input row.
color
TColor
Active-state color applied to the thumb and track via intent tokens.
bgColor
TColor
elevation
TElevation
height
number | string
maxHeight
number | string
maxWidth
number | string
minHeight
number | string
minWidth
number | string
width
number | string
direction
TDirection
disabled
boolean
false
Disables the switch — prevents interaction and applies muted styling.
error
string | boolean
errorMessages
Array<string> | string
maxErrors
number | string
name
string
readonly
boolean
false
Keeps the visual appearance interactive but blocks state changes.
rules
Array<any>
modelValue
any
Bound value of the switch. Bind with v-model.
validateOn
TValidateOn
validationValue
any
focused
boolean
appendAvatar
string
appendIcon
TIcon
prependAvatar
string
prependIcon
TIcon
prependAriaLabel
string
appendAriaLabel
string
size
TSize | number
fontSize
TFontSize
fontWeight
TFontWeight
lineHeight
TLineHeight
label
string
Visible text label associated with the switch.
trueValue
any
falseValue
any
value
any
required
boolean
type
string
valueComparator
(a: any, b: any) => boolean
falseIcon
TIcon
trueIcon
TIcon
multiple
boolean
inline
boolean
hover
boolean | IStateEffectConfig
hoverClass
string
ripple
boolean | { class: string }
loading
TControlLoadingValue
false
Loading state. 'circular' shows a spinner in the thumb; 'line' overlays the track; 'skeleton' replaces the entire switch.
loadingText
string
active
boolean | IStateEffectConfig
activeClass
string

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:modelValue
any
Fired when the switch is toggled. Bind with v-model.
@update:focused
any
@update:indeterminate
boolean
Fired when the indeterminate state is cleared on toggle.
@focus
FocusEvent
Fired when the hidden input receives focus.
@click:label
MouseEvent
Fired when the user clicks the associated label element.
@blur
FocusEvent
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

vue

Inset & color

vue

Custom track content

vue

Écosystème

Famille

Composants du même dossier qui partagent les conventions et se composent souvent ensemble.