# Toggle Group Choose one option or apply several independent formatting tools in a group of related buttons. [Interactive guide](/docs/components/toggle-group) · Forge 3.2.0 Use the API for your installed version. Run `npx --no-install wss3-forge api --json` inside the project. ## Implementation guidance ### When to use it Use single selection for mutually exclusive choices and multiple selection for independent tools. ### How to compose it Choose the installed entry first. The root data-driven value is an array of IDs even for single selection. Compound API modes differ by backend. ### What to verify Confirm arrow navigation skips disabled items and that the callback returns the shape expected by the app. ## Usage ```tsx import { ToggleGroup, ToggleGroupItem } from 'wss3-forge' ``` - Give the group an accessible name and label each icon-only item. Arrow keys move between enabled items along the group’s orientation. - Use single selection for alternatives and multiple selection for independent tools. The root and Radix compound entries use type. Base UI accepts multiple and React Aria accepts selectionMode. - The root data-driven API accepts items and uses an array of IDs with value or defaultValue, including in single-selection mode. - Set spacing to zero to join adjacent controls. An outline item uses the secondary surface and a stronger fill when selected. ```tsx List Grid ``` ## Runnable examples ### Formatting ```tsx import { TextBold16Regular, TextItalic16Regular, TextUnderline16Regular } from '@fluentui/react-icons' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' export default function FormattingControls() { return } ``` ### Composition ```tsx import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' export default function ViewOptions() { return List Grid } ``` ### Outline ```tsx import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' export default function CallFilter() { return All Missed } ``` ### Size ```tsx import { VStack } from 'wss3-forge' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' function PositionOptions({ size }: { size: 'sm' | 'default' }) { return {['Top', 'Bottom', 'Left', 'Right'].map(side => ( {side} ))} } export default function Sizes() { return } ``` ### Spacing ```tsx import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' export default function SpacedPositions() { return {['Top', 'Bottom', 'Left', 'Right'].map(side => ( {side} ))} } ``` ### Vertical ```tsx import { TextBold16Regular, TextItalic16Regular, TextUnderline16Regular } from '@fluentui/react-icons' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' export default function VerticalFormatting() { return } ``` ### Disabled ```tsx import { TextBold16Regular, TextItalic16Regular, TextUnderline16Regular } from '@fluentui/react-icons' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' export default function DisabledFormatting() { return } ``` ### Custom ```tsx import { useState } from 'react' import { Text, VStack } from 'wss3-forge' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' const weights = [{ label: 'Light', weight: 300 }, { label: 'Normal', weight: 400 }, { label: 'Medium', weight: 500 }, { label: 'Bold', weight: 700 }] export default function FontWeight() { const [weight, setWeight] = useState('Normal') return Font weight { if (values[0]) setWeight(values[0]) }} variant="outline" size="lg" spacing={2} style={{ maxWidth: '100%', flexWrap: 'wrap' }}> {weights.map(option => {option.label} )} Use font-{weight.toLowerCase()} to set the font weight. } ``` ### RTL ```tsx import { useState } from 'react' import { Board16Regular, Grid16Regular, List16Regular } from '@fluentui/react-icons' import { Select, VStack } from 'wss3-forge' import { DirectionProvider, ToggleGroup, ToggleGroupItem } from 'wss3-forge/base-ui' export default function LocalizedView() { const [language, setLanguage] = useState('ar') const arabic = language === 'ar' const direction = arabic ? 'rtl' : 'ltr' return
} ``` ### Radix Set type to single or multiple. Use a string for single selection and an array for multiple selection. Set dir for right-to-left navigation. ```sh npm install wss3-forge radix-ui ``` [Radix API reference](https://www.radix-ui.com/primitives/docs/components/toggle-group) ```tsx import { TextBold16Regular, TextItalic16Regular, TextUnderline16Regular } from '@fluentui/react-icons' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' export default function FormattingControls() { return } ``` #### Composition ```tsx import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' export default function ViewOptions() { return List Grid } ``` #### Outline ```tsx import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' export default function CallFilter() { return All Missed } ``` #### Size ```tsx import { VStack } from 'wss3-forge' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' function PositionOptions({ size }: { size: 'sm' | 'default' }) { return {['Top', 'Bottom', 'Left', 'Right'].map(side => ( {side} ))} } export default function Sizes() { return } ``` #### Spacing ```tsx import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' export default function SpacedPositions() { return {['Top', 'Bottom', 'Left', 'Right'].map(side => ( {side} ))} } ``` #### Vertical ```tsx import { TextBold16Regular, TextItalic16Regular, TextUnderline16Regular } from '@fluentui/react-icons' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' export default function VerticalFormatting() { return } ``` #### Disabled ```tsx import { TextBold16Regular, TextItalic16Regular, TextUnderline16Regular } from '@fluentui/react-icons' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' export default function DisabledFormatting() { return } ``` #### Custom ```tsx import { useState } from 'react' import { Text, VStack } from 'wss3-forge' import { ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' const weights = [{ label: 'Light', weight: 300 }, { label: 'Normal', weight: 400 }, { label: 'Medium', weight: 500 }, { label: 'Bold', weight: 700 }] export default function FontWeight() { const [weight, setWeight] = useState('Normal') return Font weight { if (value) setWeight(value) }} variant="outline" size="lg" spacing={2} style={{ maxWidth: '100%', flexWrap: 'wrap' }}> {weights.map(option => {option.label} )} Use font-{weight.toLowerCase()} to set the font weight. } ``` #### RTL ```tsx import { useState } from 'react' import { Board16Regular, Grid16Regular, List16Regular } from '@fluentui/react-icons' import { Select, VStack } from 'wss3-forge' import { DirectionProvider, ToggleGroup, ToggleGroupItem } from 'wss3-forge/radix' export default function LocalizedView() { const [language, setLanguage] = useState('ar') const arabic = language === 'ar' const direction = arabic ? 'rtl' : 'ltr' return
} ``` ## Root package API ### ToggleGroup Props type: `ToggleGroupProps | CompoundToggleGroupProps` Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, ToggleGroupImplMultipleProps, ToggleGroupImplProps, ToggleGroupImplSingleProps, ToggleGroupMultipleProps, ToggleGroupSingleProps - `items?` — `readonly ToggleGroupItem[]` - `value?` — `readonly string[] | string | undefined | string[] | undefined` The controlled stateful value of the item that is pressed. - `defaultValue?` — `readonly string[]` - `onValueChange?` — `(value: string[]) => void` - `selectionMode?` — `'single' | 'multiple'` Options `"single"`, `"multiple"`. - `orientation?` — `'horizontal' | 'vertical' | ("horizontal" | "vertical") | undefined` Options `"horizontal"`, `"vertical"`. - `required?` — `boolean` - `disabled?` — `boolean` - `size?` — `ButtonProps['size'] | 'sm' | 'default' | 'lg' | null` Options `null`, `"default"`, `"icon"`, `"sm"`, `"md"`, `"lg"`, `"xs"`, `"xl"`, `"icon-xs"`, `"icon-sm"`, `"icon-lg"`, `"icon-xl"`. - `type?` — `"single" | "multiple"` - `variant?` — `'default' | 'outline' | null` Options `null`, `"default"`, `"outline"`. - `spacing?` — `number` Default `2`. Gap in 4px units. Zero joins adjacent item borders. - `ref?` — `React.LegacyRef | undefined` #### ToggleGroupProps Native attributes: AriaAttributes, DOMAttributes, HTMLAttributes - `items` — `readonly ToggleGroupItem[]` - `value?` — `readonly string[]` - `defaultValue?` — `readonly string[]` - `onValueChange?` — `(value: string[]) => void` - `selectionMode?` — `'single' | 'multiple'` Options `"single"`, `"multiple"`. - `orientation?` — `'horizontal' | 'vertical'` Options `"horizontal"`, `"vertical"`. - `required?` — `boolean` - `disabled?` — `boolean` - `size?` — `ButtonProps['size']` Options `null`, `"default"`, `"icon"`, `"sm"`, `"md"`, `"lg"`, `"xs"`, `"xl"`, `"icon-xs"`, `"icon-sm"`, `"icon-lg"`, `"icon-xl"`. #### type="single" Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, ToggleGroupImplProps, ToggleGroupImplSingleProps, ToggleGroupSingleProps - `orientation?` — `("horizontal" | "vertical") | undefined` Options `"horizontal"`, `"vertical"`. - `type` — `"single"` - `value?` — `string | undefined` The controlled stateful value of the item that is pressed. - `variant?` — `'default' | 'outline' | null` Options `null`, `"default"`, `"outline"`. - `size?` — `'sm' | 'default' | 'lg' | null` Options `null`, `"default"`, `"sm"`, `"lg"`. - `spacing?` — `number` Default `2`. Gap in 4px units. Zero joins adjacent item borders. #### type="multiple" Native attributes: AriaAttributes, Attributes, DOMAttributes, HTMLAttributes, ToggleGroupImplMultipleProps, ToggleGroupImplProps, ToggleGroupMultipleProps - `orientation?` — `("horizontal" | "vertical") | undefined` Options `"horizontal"`, `"vertical"`. - `type` — `"multiple"` - `value?` — `string[] | undefined` The controlled stateful value of the items that are pressed. - `variant?` — `'default' | 'outline' | null` Options `null`, `"default"`, `"outline"`. - `size?` — `'sm' | 'default' | 'lg' | null` Options `null`, `"default"`, `"sm"`, `"lg"`. - `spacing?` — `number` Default `2`. Gap in 4px units. Zero joins adjacent item borders. ### ToggleGroupItem Props type: `Omit, "ref"> & Omit & React.RefAttributes` Native attributes: AriaAttributes, Attributes, ButtonHTMLAttributes, DOMAttributes, HTMLAttributes, RefAttributes, ToggleGroupItemImplProps - `variant?` — `'default' | 'outline' | null` Options `null`, `"default"`, `"outline"`. - `size?` — `'sm' | 'default' | 'lg' | null` Options `null`, `"default"`, `"sm"`, `"lg"`. - `ref?` — `React.LegacyRef | undefined` Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). ## Related types ```ts export interface ButtonProps extends ButtonAppearanceProps, Omit, 'children'> {} export interface ToggleGroupProps extends Omit, 'children' | 'defaultValue'> { items: readonly ToggleGroupItem[] value?: readonly string[] defaultValue?: readonly string[] onValueChange?: (value: string[]) => void selectionMode?: 'single' | 'multiple' orientation?: 'horizontal' | 'vertical' required?: boolean disabled?: boolean size?: ButtonProps['size'] } export type CompoundToggleGroupProps = ComponentPropsWithoutRef & ToggleGroupAppearance export interface ToggleGroupAppearance { variant?: 'default' | 'outline' | null size?: 'sm' | 'default' | 'lg' | null /** Gap in 4px units. Zero joins adjacent item borders. * @default 2 */ spacing?: number } ``` ## Optional primitive contracts - [wss3-forge/base-ui · Toggle Group contract](/ai/skill/primitive-api/Toggle%20Group.json) - [wss3-forge/radix · Toggle Group contract](/ai/skill/primitive-api/Toggle%20Group.json) - [wss3-forge/react-aria · Toggle Group contract](/ai/skill/primitive-api/Toggle%20Group.json)