Back to Shark UI

Toggle Group

docs/components/toggle-group

latest7.9 KB
Original Source

Sections

Components

Utilities

Forms

Hooks

Toggle Group

Copy Markdown

Toggle buttons for selecting a value.

DocsAPI

PreviewCode

Installation#

CLIManual

pnpmbunnpmyarn

pnpm dlx shadcn@latest add @shark/toggle-group

Anatomy#

ToggleGroup
└── ToggleGroupItem

Usage#

import { 
  ToggleGroup, 
  ToggleGroupItem 
} from "@/components/ui/toggle-group";
<ToggleGroup>
  <ToggleGroupItem value="1">Item 1</ToggleGroupItem>
  <ToggleGroupItem value="2">Item 2</ToggleGroupItem>
</ToggleGroup>

Controlled#

Use the value and onValueChange props to control the toggle group state programmatically.

PreviewCode

bold

States#

Disabled#

Disable the entire group with the disabled prop.

PreviewCode

With disabled toggle#

Disable individual toggles by setting disabled on a specific item.

PreviewCode

Orientation#

Use orientation to change the orientation of the toggle group.

Horizontal#

PreviewCode

Vertical#

PreviewCode

Variant#

Use variant to change the visual style of the toggle buttons.

Ghost#

PreviewCode

Outline#

PreviewCode

Examples#

With spacing#

Use spacing to add space between buttons.

PreviewCode

Single selection#

Use multiple={false} to allow only one toggle to be selected at a time.

PreviewCode

Custom toggle group#

A custom toggle group example with a custom styling for font weight selection.

PreviewCode

Font Weight AaLightAaNormalAaMediumAaBold

API Reference#

ToggleGroup#

Root component. Provides shared variant and size to child toggles via context.

PropTypeDefault
variant`"outline""ghost"`
size`"sm""md"
spacing`"0""1"
multiplebooleantrue
defaultValuestring[]-
valuestring[]-
onValueChange(details: ValueChangeDetails) => void-
orientation`"horizontal""vertical"`
disabledbooleanfalse
classNamestring-
AttributeDefault
--gapSet from the spacing prop (default 0)

ToggleGroupItem#

Single toggle in the group. Uses Toggle internally.

PropTypeDefault
valuestringrequired
disabledbooleanfalse
classNamestring-
aria-labelstring-

For a complete list of props, see the Ark UI documentation.

[

Previous page

Toast ](/docs/components/toast)[

Next page

Toggle Tooltip ](/docs/components/toggle-tooltip)

On This Page

InstallationAnatomyUsageControlledStatesDisabledWith disabled toggleOrientationHorizontalVerticalVariantGhostOutlineExamplesWith spacingSingle selectionCustom toggle groupAPI ReferenceToggleGroupToggleGroupItem