Props
| Name | Type | Default | Description |
|---|---|---|---|
autofocus | Booleanish | undefined | - | Sets autofocus on page load. |
checked | boolean | undefined | - | Defines the input as checked. Paints the control from state you own elsewhere and wins over |
description | string | undefined | - | Descriptive text displayed below the label and above the input. Unlike the hint it is always
visible, and it is linked to the input via Always visible and tied to the control through |
direction | InputDirection | undefined | "auto" | Direction of the layout of the component. Can either be a predefined value or a pattern separated by a space like |
disabled | boolean | undefined | false | Disables the component. |
errors | string | string[] | undefined | - | Can be a string or an array of string containing the messages to display.
They render in an |
falseValue | any | - | Value of the input when unchecked. It handles any kind of serializable object. See example |
hasErrors | boolean | undefined | false | Define if the component should be in an error state. It usually attaches a CSS class for styling purposes. |
hasWarnings | boolean | undefined | false | Define if the component should be in a warning state.
Same chrome as errors with |
hideLabel | boolean | undefined | false | Visually hides the label of the input while maintaining accessibility. |
hint | string | undefined | - | Text box to be displayed near the input, usually to indicate instructions. |
id | string | undefined | - | The identifier of the component. |
indeterminate | boolean | undefined | false | Sets the input in an indeterminate state. Parks the thumb midway, for a master switch whose children disagree. Visual only — the model keeps its value, and the component re-asserts the state after clicks because the DOM resets it natively. See example |
inputPosition | "left" | "center" | "right" | undefined | "left" | Sets the alignment of the input. Since inputs are inline block they can be aligned just as text can. |
labelrequired | string | - | Text content of the label of the element. Required — it is the accessible name of the switch. Do not add ARIA of your own: the control already exposes |
labelPosition | "left" | "center" | "right" | undefined | - | Sets the text alignment of the label. |
modelValue | any | - | Used by v-model. Can be any serializable type. |
name | string | undefined | - | Defines the name of the input. |
persistentHint | boolean | undefined | false | Keeps the hint displayed. |
pt | PtMap<TogglePtPart, CheckablePtState> | undefined | - | Passthrough, object form: the same keys as the |
pt:description | PtValue | undefined | - | |
pt:description:checked | PtValue | undefined | - | |
pt:description:disabled | PtValue | undefined | - | |
pt:description:errors | PtValue | undefined | - | |
pt:description:focus-visible | PtValue | undefined | - | |
pt:description:focused | PtValue | undefined | - | |
pt:description:indeterminate | PtValue | undefined | - | |
pt:description:readonly | PtValue | undefined | - | |
pt:description:warnings | PtValue | undefined | - | |
pt:hint | PtValue | undefined | - | |
pt:hint:checked | PtValue | undefined | - | |
pt:hint:disabled | PtValue | undefined | - | |
pt:hint:errors | PtValue | undefined | - | |
pt:hint:focus-visible | PtValue | undefined | - | |
pt:hint:focused | PtValue | undefined | - | |
pt:hint:indeterminate | PtValue | undefined | - | |
pt:hint:readonly | PtValue | undefined | - | |
pt:hint:warnings | PtValue | undefined | - | |
pt:icon | PtValue | undefined | - | |
pt:icon:checked | PtValue | undefined | - | |
pt:icon:disabled | PtValue | undefined | - | |
pt:icon:errors | PtValue | undefined | - | |
pt:icon:focus-visible | PtValue | undefined | - | |
pt:icon:focused | PtValue | undefined | - | |
pt:icon:indeterminate | PtValue | undefined | - | |
pt:icon:readonly | PtValue | undefined | - | |
pt:icon:warnings | PtValue | undefined | - | |
pt:label | PtValue | undefined | - | |
pt:label:checked | PtValue | undefined | - | |
pt:label:disabled | PtValue | undefined | - | |
pt:label:errors | PtValue | undefined | - | |
pt:label:focus-visible | PtValue | undefined | - | |
pt:label:focused | PtValue | undefined | - | |
pt:label:indeterminate | PtValue | undefined | - | |
pt:label:readonly | PtValue | undefined | - | |
pt:label:warnings | PtValue | undefined | - | |
pt:message | PtValue | undefined | - | |
pt:message:checked | PtValue | undefined | - | |
pt:message:disabled | PtValue | undefined | - | |
pt:message:errors | PtValue | undefined | - | |
pt:message:focus-visible | PtValue | undefined | - | |
pt:message:focused | PtValue | undefined | - | |
pt:message:indeterminate | PtValue | undefined | - | |
pt:message:readonly | PtValue | undefined | - | |
pt:message:warnings | PtValue | undefined | - | |
pt:root | PtValue | undefined | - | |
pt:root:checked | PtValue | undefined | - | |
pt:root:disabled | PtValue | undefined | - | |
pt:root:errors | PtValue | undefined | - | |
pt:root:focus-visible | PtValue | undefined | - | |
pt:root:focused | PtValue | undefined | - | |
pt:root:indeterminate | PtValue | undefined | - | |
pt:root:readonly | PtValue | undefined | - | |
pt:root:warnings | PtValue | undefined | - | |
readonly | boolean | undefined | false | Sets the input in a readonly state. The right state for a switch whose change is in flight, and for admin-locked settings. It sets no native |
required | boolean | undefined | false | Sets the input as required. |
reverse | boolean | undefined | false | Reverses the layout: in every direction the order of the label and the input is swapped from the standard arrangement. Its meaning inverted in v3 and the compiler cannot see it. The default rendering is unchanged, but a v2 |
submitWhenFalse | boolean | undefined | false | Will submit "falseValue" if the input is not checked. Otherwise "trueValue" will be submitted. Only for classic form posts: an unchecked switch otherwise submits nothing. The full value contract is shared with |
trueValue | any | - | Value of the input when checked. It handles any kind of serializable object. Point it and |
warnings | string | string[] | undefined | - | Warning messages to display beneath the field, in their own |
v-model
Values kept in sync through v-model.
| Name | Type | Description |
|---|---|---|
modelValue | any | Carries the mapped |
Events
| Name | Type | Description |
|---|---|---|
blur | (event: "blur", event: FocusEvent): void | |
change | (event: "change", event: Event): void | |
click | (event: "click", event: MouseEvent): void | |
focus | (event: "focus", event: FocusEvent): void | |
input | (event: "input", event: Event): void | |
keydown | (event: "keydown", event: KeyboardEvent): void | |
mousedown | (event: "mousedown", event: MouseEvent): void | |
mouseup | (event: "mouseup", event: MouseEvent): void | |
update:modelValue | (event: "update:modelValue", value: any): void | The hook for a live switch that saves itself: write optimistically here, hold the control readonly while the request is in flight, and restore the previous value on failure. See example |
Slots
The listed properties are the ones exposed to the slot scope.
| Name | Type | Description |
|---|---|---|
description | BbSwitchDescriptionSlotProps | Replaces the description text. Provided alone (no |
icon | BbCheckboxIconSlotProps | Replaces the default toggle track visual inside the switch. Receives the switch state plus the label text. Replaces the entire track and thumb, not a glyph inside them — a bare icon here leaves no track at all. Keep it when only the visual is wrong; when the whole row is wrong, drop to |
label | BbSwitchLabelSlotProps | Replaces the default label text rendered next to the switch. |
Changes from v2
Props removed or renamed in 3.0. If you are coming from v2, the answer is here.
colorremovedfails silentlyhasWarninghasWarningsfails silently