ToggleGroup
ToggleGroup is a set of related toggles, such as text alignment or Bold, Italic and Underline. Use type="single" for one choice or type="multiple" for several. Icon-only items need an aria-label.
This example also needs:
Installation
Run npx nxds-cli@latest init first if nxds isn’t set up in your app yet. See Install.
Usage
Composition
Examples
Multiple
Set type="multiple" to let users press several items at once.
Outline
Set variant="outline" on the group to style every item.
Spacing
Leave spacing at 0 for a joined control, or raise it for separate pills.
Formatting settings
Use toggle groups for text formatting and paragraph style inside a settings form.
Disabled
Disable the group to disable every item in it.
Props
ToggleGroup
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "sm" | "lg" | null | "default" | No description |
spacing | 0 | 1 | 2 | 4 | 3 | 5 | 6 | 7 | 8 | 0.5 | 1.5 | 2.5 | 3.5 | 9 | 10 | 11 | 12 | 14 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 72 | 80 | 96 | 0 | Gap between items, in spacing-scale units. |
variant | "default" | "outline" | "outline-primary" | null | "default" | No description |
ToggleGroupItem
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "sm" | "lg" | null | "default" | No description |
variant | "default" | "outline" | "outline-primary" | null | "default" | No description |
ToggleGroup is a set of related toggles, such as text alignment or Bold, Italic and Underline. Use type="single" for one choice or type="multiple" for several. Icon-only items need an aria-label.
This example also needs:
Installation
Install these components first:
Copy and paste the following code into your project.
components/toggle-group/ToggleGroup.vue components/toggle-group/ToggleGroupItem.vue components/toggle-group/index.ts components/toggle-group/toggle-group-selection.ts Keep each file at the path shown above it.
Paths are relative to
packages/vue/src/. Keep the same folders under your@/root, and the imports between files work without edits.
Usage
Examples
Multiple
Set type="multiple" to let users press several items at once.
Outline
Set variant="outline" on the group to style every item.
Spacing
Leave spacing at 0 for a joined control, or raise it for separate pills.
Formatting settings
Use toggle groups for text formatting and paragraph style inside a settings form.
Disabled
Disable the group to disable every item in it.
Props
ToggleGroup
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "sm" | "lg" | null | "default" | No description |
spacing | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | 16 | 20 | 0.5 | 1.5 | 2.5 | 3.5 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 72 | 80 | 96 | 0 | Gap between items, in spacing-scale units. |
variant | "default" | "outline" | "outline-primary" | null | "default" | No description |
ToggleGroupItem
| Prop | Type | Default | Description |
|---|---|---|---|
size | "default" | "sm" | "lg" | null | "default" | No description |
valueRequired | string | No default documented | Value the group reports while this item is pressed. |
variant | "default" | "outline" | "outline-primary" | null | "default" | No description |