Design System

Toggle reference ​

Every prop, event and attribute CToggle accepts, and what it renders. For what the component decides, see Overview. For how to write one, see Usage.

Props ​

PropTypeRequiredDefaultMeaning
modelValuebooleanYesnoneThe state, bound with v-model or with :model-value and a handler. Declared with required: true, so an omitted model warns at render
labelstringYesnoneThe text of the label, and the accessible name. Interpolated as text, with no slot to replace it
hideLabelbooleanNofalseAdds sr-only to the label. The text stays in the accessibility tree and the pairing to the input is unchanged
disabledbooleanNofalseDisables the input, dims the switch and the label, and suppresses both hover rules

id is an attribute rather than a prop. A string is taken as the input id and as the label for, and anything else is ignored in favour of a generated one.

trueValue, falseValue, invalid, readonly, tabindex, inputClass, inputStyle, ariaLabel and ariaLabelledby belong to the component library underneath and are not part of this API. The switch is on when the model is the literal true.

Events ​

EventPayloadDeclared
update:modelValueboolean, the opposite of the current stateYes
changeThe native Event, emitted after the model updateNo, forwarded as a listener
focusFocusEventNo, forwarded as a listener
blurFocusEventNo, forwarded as a listener
click, and any other listenerThe native event, delivered on the outer element of the switch rather than on the inputNo, forwarded as a listener

A forwarded listener is untyped at the call site, so an undeclared event reaches the component library without appearing in editor completion. A disabled switch emits nothing at all: the change handler returns before emitting, a disabled input cannot take focus, and the outer element takes no pointer events.

Slots ​

None. The component renders no slot of its own, so text written between its tags is discarded and the label has to go through the prop.

Axes ​

None. size, severity, variant and invalid are absent from CToggleProps rather than narrowed inside it, so the switch is 40 by 24 pixels in every state, and the danger branch the preset carries for the track border cannot be reached through this wrapper.

Attributes ​

The component sets inheritAttrs: false and binds an allow-list of data-*, aria-*, a listener, and the three names id, name and form, which is the layer contract in What the API accepts.

PassedDestination
data-*The outer element of the switch
A listenerConsumed as an event where the component library declares one, otherwise the outer element of the switch
aria-*The input, merged after the attributes the component library binds, so a passed aria-label replaces the label as the accessible name
idThe input id, and the label for
name, formThe outer element of the switch, where neither has an effect
class, style, pt, labelClass, and any other name outside the allow-list, such as trueValue, invalid, readonly, tabindex or ariaLabelDropped

DOM ​

div          the wrapper, display flex, items centred, 8px gap
  div        the outer element of the switch, 40 by 24,
             carrying data-p-checked and data-p-disabled
    input    type=checkbox, role=switch, absolute, opacity 0, class peer
    div      the track, filling the outer element, its ::before drawing the knob
      div    the handle, with no class and nothing painting it
  label      for the input id, caption role, sr-only under hideLabel

The preset defines a class for the outer element, the track and the input only, so the handle stays empty and the knob that moves is the track's ::before.

ARIA ​

AttributeSet by the component
The accessible nameThe label, paired to the input by for and id
roleswitch, on the input
aria-checkedtrue or false, matching the model
aria-label, aria-labelledbyAbsent unless a caller forwards a kebab-case attribute
aria-invalidAbsent unless a caller forwards a kebab-case attribute, since the invalid prop underneath cannot be reached
aria-describedbyAbsent unless a caller forwards a kebab-case attribute. The description branch of the shared composable is unused here
tabindexAbsent, since the name sits outside the allow-list and the prop underneath cannot be reached, so the input keeps its native tab position

Geometry ​

Pixel values below are at the default interface text setting of 14. The switch does not move with that setting and the label does.

PartValue
Track40 by 24 pixels, 1 pixel border, corner 16 pixels from rounded-2xl, which the interface theme restores
Knob16 by 16 pixels, fully round, 4 pixels below the outer top edge in both states
Knob inset and travel5 pixels from the left edge when off, 3 pixels from the right edge when on, 16 pixels of travel between them. The offset is measured inside the 1 pixel border while the track width is measured outside it, which is where the 2 pixel difference comes from
Gap, switch to label8 pixels, out of the layout under hideLabel
WrapperDisplay flex, block level, 24 pixels tall, as wide as its parent
LabelCaption role, 12 pixel type on a 16 pixel line, weight 400, no colour of its own
Track transition200ms on colour, over the 150ms state duration, on the standard curve
Knob transition200ms on the initial ease curve, since the preset sets a duration on the pseudo-element and no timing function
Reduced motionThe interface resets transition on elements and pseudo-elements, so the knob jumps and the fill changes at once
Disabled0.6 opacity, and pointer-events: none on the switch rather than on the label
Focus indicatorA 2 pixel line-focus outline at a 2 pixel offset, drawn on the track by the interface stylesheet, outer bounds 48 by 32

Colours ​

StateTrack fillBorderKnob
Offsurface-subtleline-strongfill-neutral
Off, hoveredsurface-hoverline-strongfill-neutral
Onfill-secondarytransparentfg-on-secondary
On, hoveredfill-secondary-hovertransparentfg-on-secondary

A hover row is reached through peer-hover on the track, driven by the transparent input covering the whole switch, so anywhere on the switch counts. Disabled draws whichever of the two resting rows applies at 0.6 opacity and suppresses both hover rows. fill-secondary and fg-on-secondary are single values rather than light and dark pairs, so a switch that is on renders the same amber in both appearances.

Measured contrast ​

Computed from the token values, converted to sRGB and put through the WCAG 2 formula. The floors are in accessibility.

PairingLightDark
The knob on the off track3.433.48
The knob on the off hovered track2.812.83
The knob on the on track7.557.55
The knob on the on hovered track6.227.92
The border on the off track2.932.91
The border on the page surface3.173.11