Skip to content

BbSwitchGroup

Manages grouped switch options with shared behavior.

import { BbSwitchGroup } from 'bitboss-ui';

On this page

Props

NameTypeDefaultDescription
autofocusBooleanish | undefined-

Sets autofocus on page load.

compactboolean | undefinedfalse

Displays the component in a compact version.

See example
dependenciesunknown[] | undefined-

Defines an array of dependencies that will trigger actions in the component upon change.

depsDebounceTimenumber | undefined-

Timeout used to debounce response to changes to dependencies.

descriptionstring | 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 aria-describedby (after any errors / warnings, before the hint).

One description for the whole set. It is also the only place max and selectable get explained — a switch that refuses to move with no reason on screen reads as broken.

See example
directionInputDirection | undefined-

Direction of the layout of the component. Can either be a predefined value or a pattern separated by a space like xx xxxxx.

disabledboolean | undefinedfalse

Disables the component.

Currently exempts options that are already on, so a disabled group can still be switched off. Use readonly to lock a group that carries a selection.

See example
enforceCoherenceboolean | undefinedfalse

If coherence is enforced the input cannot have a modelValue that is incoherent with its current items. e.g. You cannot set v-model to a user that is not present in the items passed. modelValue will be reset upon incoherence.

errorsstring | string[] | undefined-

Can be a string or an array of string containing the messages to display. They render in an aria-live="polite" region (announced when they appear) and, while the list is non-empty, are referenced FIRST from the control's aria-describedby, so the reason the field is invalid is re-read whenever the control regains focus.

One channel for the fieldset. On an instant-save group it is where a refused write explains itself — pair it with a toast, since the group may be off screen by then.

See example
hasErrorsboolean | undefinedfalse

Define if the component should be in an error state. It usually attaches a CSS class for styling purposes.

hasWarningsboolean | undefinedfalse

Define if the component should be in a warning state. Same chrome as errors with --bb-warn; errors take priority.

hideLabelboolean | undefinedfalse

Visually hides each option's label text (the text rendered next to every input) while keeping it accessible to screen readers. Does not affect the fieldset legend — use hideLegend for that.

hideLegendboolean | undefinedfalse

Visually hides the legend of the fieldset while maintaining accessibility.

hintstring | undefined-

Text box to be displayed near the input, usually to indicate instructions.

idstring | undefined-

The identifier of the component.

inputDirection"horizontal" | "vertical" | undefined-

Defines the direction of the inputs in the fieldset.

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.

itemPropsBbOptionGroupItemProps<T> | undefined-

ADDITIONAL row fields resolved from each item — never its text or value (those stay on itemText / itemValue). Option groups accept one field: - description — a muted line under the option label, beside the control; it may wrap. Either an object with a path or getter per field ({ description: 'email' }) or a function returning the fields ((item) => ({ description: item.email })). Without it no field renders — an item's own description is never read implicitly — and an empty value renders nothing for that item. The description is announced as the option's description, never part of its name. To disable individual options use selectable.

itemsrequiredT[] | ((prefill: boolean, modelValue?: any) => T[] | Promise<T[]>)-

Used to retrieve items; can be an array or a function.

Same mapping as BbCheckboxGroup, down to the accessors and the silent de-duplication by resolved value.

See example
itemTextItemAccessor<T, string> | undefined-

Defines a path that returns a property of the object to use as text or a function that returns a string.

See example
itemValueItemAccessor<T> | undefined-

Defines a path that returns a property of the object to use as value or a function that returns any value.

See example
legendrequiredstring-

Text content of the legend.

Required. It names the set of states, which is what a screen reader announces before the first switch.

See example
legendMode"outside" | "inside" | undefined-

Legend rendering mode. 'outside' renders the legend above the fieldset in the normal flow; 'inside' overlays the legend inside the fieldset border. Floating mode is not supported for option groups (checkbox, radio or switch) — there is no single field for the legend to float against.

legendPosition"left" | "center" | "right" | undefined-

Sets the text alignment of the label.

loadingTextstring | undefined-

String displayed while items are being loaded.

maxnumber | undefined-

Maximum number of selected items.

Once the cap is reached the switches that are off render disabled and the ones that are on stay live, so the user swaps rather than getting stuck.

See example
modelValuerequiredany-

Used by v-model. Can be an array of any serializable type.

modelValueDebounceTimenumber | undefined-

Timeout used to debounce response to changes to modelValue.

multipleboolean | undefinedtrue

Enables multi-selection behavior. When true, modelValue must be an array. When false, modelValue should be a single value.

v2 advertised this prop and never forwarded it: a group set to single-select still emitted an array. v3 honours it, so a model written expecting an array now receives a bare value or null, with no warning.

See example
namestring | undefined-

Defines the name of the input.

noDataTextstring | undefined-

String displayed when there are no items to display.

persistentHintboolean | undefinedfalse

Keeps the hint displayed.

ptGroupPtMap<T> | undefined-

Passthrough, object form: the same keys as the pt:* attributes without the prefix. See the pt:<part> row.

pt:descriptionPtValue | undefined-
pt:description:disabledPtValue | undefined-
pt:description:errorsPtValue | undefined-
pt:description:has-valuePtValue | undefined-
pt:description:loadingPtValue | undefined-
pt:description:readonlyPtValue | undefined-
pt:description:warningsPtValue | undefined-
pt:hintPtValue | undefined-
pt:hint:disabledPtValue | undefined-
pt:hint:errorsPtValue | undefined-
pt:hint:has-valuePtValue | undefined-
pt:hint:loadingPtValue | undefined-
pt:hint:readonlyPtValue | undefined-
pt:hint:warningsPtValue | undefined-
pt:iconPtValue | ((ctx: PtItemCtx<T, GroupPtState>) => PtItemResult) | undefined-
pt:icon:checkedPtValue | undefined-
pt:icon:disabledPtValue | undefined-
pt:icon:errorsPtValue | undefined-
pt:icon:focus-visiblePtValue | undefined-
pt:icon:focusedPtValue | undefined-
pt:icon:has-valuePtValue | undefined-
pt:icon:loadingPtValue | undefined-
pt:icon:readonlyPtValue | undefined-
pt:icon:warningsPtValue | undefined-
pt:itemPtValue | ((ctx: PtItemCtx<T, GroupPtState>) => PtItemResult) | undefined-
pt:item-descriptionPtValue | ((ctx: PtItemCtx<T, GroupPtState>) => PtItemResult) | undefined-
pt:item-description:checkedPtValue | undefined-
pt:item-description:disabledPtValue | undefined-
pt:item-description:errorsPtValue | undefined-
pt:item-description:focus-visiblePtValue | undefined-
pt:item-description:focusedPtValue | undefined-
pt:item-description:has-valuePtValue | undefined-
pt:item-description:loadingPtValue | undefined-
pt:item-description:readonlyPtValue | undefined-
pt:item-description:warningsPtValue | undefined-
pt:item:checkedPtValue | undefined-
pt:item:disabledPtValue | undefined-
pt:item:errorsPtValue | undefined-
pt:item:focus-visiblePtValue | undefined-
pt:item:focusedPtValue | undefined-
pt:item:has-valuePtValue | undefined-
pt:item:loadingPtValue | undefined-
pt:item:readonlyPtValue | undefined-
pt:item:warningsPtValue | undefined-
pt:labelPtValue | ((ctx: PtItemCtx<T, GroupPtState>) => PtItemResult) | undefined-
pt:label:checkedPtValue | undefined-
pt:label:disabledPtValue | undefined-
pt:label:errorsPtValue | undefined-
pt:label:focus-visiblePtValue | undefined-
pt:label:focusedPtValue | undefined-
pt:label:has-valuePtValue | undefined-
pt:label:loadingPtValue | undefined-
pt:label:readonlyPtValue | undefined-
pt:label:warningsPtValue | undefined-
pt:legendPtValue | undefined-
pt:legend:disabledPtValue | undefined-
pt:legend:errorsPtValue | undefined-
pt:legend:has-valuePtValue | undefined-
pt:legend:loadingPtValue | undefined-
pt:legend:readonlyPtValue | undefined-
pt:legend:warningsPtValue | undefined-
pt:listPtValue | undefined-
pt:list:disabledPtValue | undefined-
pt:list:errorsPtValue | undefined-
pt:list:has-valuePtValue | undefined-
pt:list:loadingPtValue | undefined-
pt:list:readonlyPtValue | undefined-
pt:list:warningsPtValue | undefined-
pt:messagePtValue | undefined-
pt:message:disabledPtValue | undefined-
pt:message:errorsPtValue | undefined-
pt:message:has-valuePtValue | undefined-
pt:message:loadingPtValue | undefined-
pt:message:readonlyPtValue | undefined-
pt:message:warningsPtValue | undefined-
pt:rootPtValue | undefined-
pt:root:disabledPtValue | undefined-
pt:root:errorsPtValue | undefined-
pt:root:has-valuePtValue | undefined-
pt:root:loadingPtValue | undefined-
pt:root:readonlyPtValue | undefined-
pt:root:warningsPtValue | undefined-
readonlyboolean | undefinedfalse

Sets the input in a readonly state.

Keeps the switches focusable and submitted while swallowing changes — which is what an instant-save group holds itself in while its request is in flight.

See example
reverseboolean | undefinedfalse

Reverses the layout. Applicable in every direction the order of the label and the input is swapped.

selectableboolean | ((item: T) => boolean) | undefinedtrue

Defines whether options are selectable. Can be a global boolean that affects all options or a function that accepts an item and returns a boolean that only affects that item. Non-selectable options are rendered disabled.

A boolean for the group or a predicate over the item, resolving through the same per-option path as max. Where v2's per-item disabled field went: that field is inert in v3, silently, so locked feature flags become flippable.

See example
warningsstring | string[] | undefined-

Warning messages to display beneath the field, in their own aria-live region and amber (--bb-text-warn). A string or array; a non-empty list implies the warning state. Errors suppress warnings when both are set. While displayed they are also referenced from the control's aria-describedby, after any errors and before the description/hint.

v-model

Values kept in sync through v-model.

NameTypeDescription
modelValueany

The array of the options that are on, re-emitted in full on every change. An instant-save handler receives the whole next array and diffs it against the previous one; reading the single toggle off a @change event is how the two drift apart.

See example

Events

NameTypeDescription
active(e: "active"): void

Emitted when the group becomes active (focus/click enters it).

blur(e: "blur", event: FocusEvent): void

Emitted when one of the generated checkbox inputs loses focus. Forwards the original DOM FocusEvent.

change(e: "change", event: Event): void

Emitted when an option is toggled. Forwards the original DOM Event from the checkbox input.

click(e: "click", event: MouseEvent): void

Emitted when one of the generated checkbox inputs is clicked. Forwards the original DOM MouseEvent.

focus(e: "focus", event: FocusEvent): void

Emitted when one of the generated checkbox inputs receives focus. Forwards the original DOM FocusEvent.

inactive(e: "inactive"): void

Emitted when focus/click moves outside the group after it was active. Useful for validation-on-blur flows at group level.

input(e: "input", event: Event): void

Emitted on native input events from generated checkbox inputs. Forwards the original DOM Event.

keydown(e: "keydown", event: KeyboardEvent): void

Emitted for keyboard interaction on generated checkbox inputs. Forwards the original DOM KeyboardEvent.

mousedown(e: "mousedown", event: MouseEvent): void

Emitted when a pointing device button is pressed over a checkbox input. Forwards the original DOM MouseEvent.

mouseup(e: "mouseup", event: MouseEvent): void

Emitted when a pointing device button is released over a checkbox input. Forwards the original DOM MouseEvent.

update:modelValue(e: "update:modelValue", value: any): void

Emitted with the coherent next selection array whenever selection changes.

Bind this together with :model-value instead of using v-model whenever a failed write has to put the previous value back.

See example

Slots

The listed properties are the ones exposed to the slot scope.

NameTypeDescription
appendobject

Content rendered after the last option, inside the options container.

descriptionBbSwitchGroupDescriptionSlotProps

Replaces the description text. Provided alone (no description prop) it still renders the description region and wires it into aria-describedby.

iconBbSwitchGroupIconSlotProps<T>

Replaces the default switch track visual for each option. Receives the switch state plus the source item and its display text.

Replaces the entire track and thumb per option, not a glyph inside them, so the slot content has to communicate on, off and focused by itself. The input underneath keeps role="switch" either way.

See example
labelBbSwitchGroupLabelSlotProps<T>

Replaces the default label text for each option.

legendBbSwitchGroupLegendSlotProps

Replaces the default fieldset legend text for the group.

loadingobject

Content shown while options are loading (replaces the default loading text).

no-dataobject

Content shown when no options are available (replaces the default "no data" text).

prependobject

Content rendered before the first option, inside the options container.

Changes from v2

Props removed or renamed in 3.0. If you are coming from v2, the answer is here.

  • colorremovedfails silently
  • hasWarninghasWarningsfails silently
  • labelPositionlegendPositionfails silently