--- package: "@svenskaspel/ui" version: "4.5.0" document_type: "component-documentation" source: "@svenskaspel/ui/docs/toggle-group.md" canonical_url: "/components/toggle-group" usage_source: "src/app/(docs)/components/toggle-group/page.mdx" --- # Toggle Group Toggle Group is used to make selections, typically within a form setting. ![Toggle group](/images/components/toggle-group/toggle-group-figma-4f2a0.webp) *** ## Usage Use a toggle group to allow the user to make selections within a interface, either single mutually exclusive options or multiple independent options. ### Interaction states #### Default ![Interaction states – 1](/images/components/toggle-group/toggle-group-figma-0c89b.webp) The default state, prior to to user interaction. #### Pressed ![Interaction states – 2](/images/components/toggle-group/toggle-group-figma-f1834.webp) The button in the toggle group is currently activated. ![Interaction states – 1](/images/components/toggle-group/toggle-group-figma-a9115.webp) > **Do:** Use short, clear, and concise labels in a logical order. ![Interaction states – 2](/images/components/toggle-group/toggle-group-figma-d047e.webp) > **Don't:** Avoid long or unclear labels *** ## Formatting ### Anatomy The toggle group consists of a set of togglable buttons. ![Anatomy](/images/components/toggle-group/toggle-group-figma-5dfe7.webp) 1. Container 2. Label 3. Selected button 4. Unselected button *** ## Behaviour ### Single and multi select Toggle group can be configured to either allow only a single option, typically for making a selection between mutually exclusive options or toggling between states. Alternatively toggle group can be configured to allow multiple options simultaneously, e.g. in a filtering function, where each option can be toggled independently. The two variants have slightly different designs, indicating their function. ![Single and multi select – 1](/images/components/toggle-group/toggle-group-figma-e66e4.webp) Single select – only one option can be active at one time. ![Single and multi select – 2](/images/components/toggle-group/toggle-group-figma-41f04.webp) Multi select – multiple options can be active simultaneously. ### Multiple rows Toggle group allows for multiple row configuration. Add additional rows if the available options in the group exceeds 5 or if the label texts are long. ![Multiple rows](/images/components/toggle-group/toggle-group-figma-0021e.webp) Examples of Toggle groups featuring multiple rows. *** ## Modify ### Emphasis The Toggle group is available in two emphasis variants: medium and low. Use the medium variant as the default. It is the standard choice for most use cases and provides a clear level of prominence within the interface. Use the low variant when the Toggle group is already visually encapsulated by a surrounding container or layout. #### Medium emphasis ![Emphasis – 1](/images/components/toggle-group/toggle-group-figma-fe869.webp) Example of a typical use of the Toggle group, where it appears as a standalone control and needs a clear level of prominence in the layout. #### Low emphasis ![Emphasis – 2](/images/components/toggle-group/toggle-group-figma-5f594.webp) Example of a Toggle group placed within an already encapsulated context, where a lower-emphasis treatment reduces visual weight while preserving clarity and usability. ### Sizes Toggle group is available in medium and small size. Medium is the default size and should always be used in most situations while the small variant can be used in designs where vertical screen estate is limited. ![Sizes](/images/components/toggle-group/toggle-group-figma-eaa1e.webp) Medium and small toggle groups. ### Icons A check icon within the selected element can be used to further emphasise the selected state if desired. ![Icons](/images/components/toggle-group/toggle-group-figma-b700b.webp) Selected state further emphasised with a check-icon. --- # Readme / API # Toggle Group `ToggleGroup` groups styled toggle buttons with single or multiple selection. Nova adapts Base UI's array-based primitive to a string for `type="single"` and a string array for `type="multiple"`. ## Props | Prop | Type | Default | Description | | --------------- | -------------------------------------------------------- | ------------ | ------------------------------------------------------------------------------ | | `type` | `'single' \| 'multiple'` | required | Selection mode. | | `value` | `string` or `string[]` | — | Controlled selection matching `type`. An empty string clears single selection. | | `defaultValue` | `string` or `string[]` | `''` or `[]` | Initial uncontrolled selection. | | `onValueChange` | `(value: string) => void` or `(value: string[]) => void` | — | Selection callback matching `type`. | | `emphasis` | `'medium' \| 'low'` | `'medium'` | Selected appearance. | | `context` | `'base' \| 'surface'` | `'surface'` | Surface containing the group. | | `size` | `'sm' \| 'md'` | `'md'` | 36 px or 44 px minimum item size. | | `disabled` | `boolean` | `false` | Disables the group. | | `name` | `string` | — | Adds native inputs for form submission. | | `className` | `string` | — | Additional root classes. | | `children` | `React.ReactNode` | — | ToggleGroupItem elements. | The root exposes Nova's props above rather than all Base UI root props. `variant`, `size="lg"`, and `loopFocus` are not part of its public type. `ToggleGroupItem` requires a string `value` and accepts Base UI Toggle props (except its original `value` type), including `disabled`, `render`, and `className`. Appearance comes from the group. ## Single selection ```tsx import * as React from 'react'; import { ToggleGroup, ToggleGroupItem } from '@svenskaspel/ui/react/toggle-group'; export function ViewPicker() { const [value, setValue] = React.useState('list'); return ( List Grid ); } ``` Pressing the selected item again clears the selection. Omit `value` and `onValueChange` for uncontrolled usage; use `defaultValue` to select an initial item. ## Multiple selection and forms ```tsx import * as React from 'react'; import { Button } from '@svenskaspel/ui/react/button'; import { ToggleGroup, ToggleGroupItem } from '@svenskaspel/ui/react/toggle-group'; export function SportsPicker() { const [sports, setSports] = React.useState([]); return (
{ event.preventDefault(); console.log(new FormData(event.currentTarget).getAll('sports')); }} > Soccer Tennis
); } ``` When `name` is supplied, each item has a visually hidden radio input (single) or checkbox input (multiple). Their checked state is synchronized in a client effect. Use `FormData.get` for single mode and `getAll` for multiple mode; interaction and input synchronization require client-side React. ## Styling and accessibility Both selection modes use a 4 px gap. `emphasis="medium"` uses a bordered selected surface; `emphasis="low"` uses a tinted selected background. `context` selects the surrounding surface tokens. Items use `data-pressed` for selected styling and expose `aria-pressed`; they remain buttons in single mode. Base UI manages keyboard navigation. Give icon-only items an accessible name. ToggleGroup creates an isolated stacking context. During `:focus-visible`, the focused item is raised to `--z-base-high` within that group so its ring stays above adjacent items, including groups with no gap. The group itself is not raised above surrounding content such as sticky table headers. The item's elevation is removed when keyboard focus leaves it; the shared `keyboard-focus-default` rule is unchanged. See [Toggle](/ai/components/toggle.md) for shared appearance and [Base UI Toggle Group](https://base-ui.com/react/components/toggle-group) for primitive behavior.