Glrk UI

Toggle

A wrapper for Base UI Toggle with single/multiple selection, controlled state, vertical orientation, spacing, and variant/size controls.

Basic
Default — single selection, string items
multiple — several items active simultaneously
Items format
Icon only — use aria-label for accessibility
Icon + label
Controlled
value + onValueChange — driven by external state
italic
Orientation
orientation: vertical — stacks items, arrow keys navigate vertically
Spacing
spacing — 0 = joined (default), 1+ = gap between items
Variants
variant — default / outline
Sizes
size — sm / default / lg
Disabled
disabled — entire group non-interactive

Installation

npx shadcn@latest add @glrk-ui/toggle

If you haven't set up the prerequisites yet, check out registry setup.

Usage

Basic

import { ToggleWrapper } from "@/components/ui/toggle"

<ToggleWrapper items={["Bold", "Italic", "Underline"]} />

Multiple selection

<ToggleWrapper items={["Bold", "Italic", "Underline"]} multiple />

Items format

Items accept primitives (string | number | boolean) or objects with label, value, and optional className / aria-label:

// Primitives
<ToggleWrapper items={["Bold", "Italic", 42, true]} />

// Icon only — always provide aria-label
<ToggleWrapper
  items={[
    { label: <Bold />, value: "bold", "aria-label": "Toggle bold" },
    { label: <Italic />, value: "italic", "aria-label": "Toggle italic" },
  ]}
/>

// Icon + label
<ToggleWrapper
  items={[
    { label: <><AlignLeft /> Left</>, value: "left" },
    { label: <><AlignCenter /> Center</>, value: "center" },
  ]}
/>

Controlled

const [value, setValue] = React.useState<string[]>(["italic"])

<ToggleWrapper
  items={["Bold", "Italic", "Underline"]}
  value={value}
  onValueChange={(v) => setValue(v)}
  multiple
/>

Orientation

<ToggleWrapper items={items} orientation="vertical" />

Arrow key navigation adjusts automatically — up/down for vertical, left/right for horizontal. Focus loops by default (loopFocus defaults to true).

Spacing

spacing={0} (default) joins items into a single connected group. Larger values add gap:

<ToggleWrapper items={items} spacing={0} />  {/* joined */}
<ToggleWrapper items={items} spacing={1} />  {/* 4px gap */}
<ToggleWrapper items={items} spacing={2} />  {/* 8px gap */}

Variants

<ToggleWrapper items={items} variant="default" />
<ToggleWrapper items={items} variant="outline" />

Sizes

<ToggleWrapper items={items} size="sm" />
<ToggleWrapper items={items} size="default" />
<ToggleWrapper items={items} size="lg" />

Disabled

<ToggleWrapper items={items} disabled />

Item CSS class

Apply shared CSS to all items via itemCls. Individual items override with their own className:

<ToggleWrapper
  items={[
    "Bold",
    { label: "Custom", value: "custom", className: "text-primary" },
  ]}
  itemCls="font-semibold"
/>

Reference

toggleItemT

Prop

Type

ToggleWrapper

Prop

Type