@usevyre/react @usevyre/vue

Toggle Group

A segmented control for choosing one or many options. Controlled — onChange emits the value, not an event. Use type="single" (string) or type="multiple" (array). Not a Switch (boolean) or ButtonGroup (layout only).


Single & multiple

The first group is single-select via options; the second is multi-select with composable ToggleItem children. Arrow keys move focus between items.

Single — view (grid)

Multiple — format (bold)

import { useState } from "react";
import { ToggleGroup, ToggleItem, Stack, Text } from "@usevyre/react";

const [view, setView] = useState<string | null>("grid");
const [fmt, setFmt] = useState<string[]>(["bold"]);

<Stack direction="column" gap="lg">
  <Stack direction="column" gap="xs">
    <Text size="sm" color="muted">Single — view ({view ?? "none"})</Text>
    <ToggleGroup
      value={view}
      onChange={setView}
      options={[
        { value: "grid", label: "Grid" },
        { value: "list", label: "List" },
        { value: "board", label: "Board" },
      ]}
    />
  </Stack>
  <Stack direction="column" gap="xs">
    <Text size="sm" color="muted">Multiple — format ({fmt.join(", ") || "none"})</Text>
    <ToggleGroup type="multiple" value={fmt} onChange={setFmt}>
      <ToggleItem value="bold">B</ToggleItem>
      <ToggleItem value="italic">I</ToggleItem>
      <ToggleItem value="underline">U</ToggleItem>
    </ToggleGroup>
  </Stack>
</Stack>

Props

Props

Prop Type Default Description
type "single" | "multiple" "single" single → value string|null; multiple → value string[].
value string | null | string[] Controlled selected value (shape depends on type).
onChange (value) => void Emits the value — string|null or string[]. Not an event.
options { value; label?; icon?; disabled? }[] Alternative to ToggleItem children for simple lists.
size "sm" | "md" | "lg" "md" Control size.
orientation "horizontal" | "vertical" "horizontal" Layout direction.
disabled boolean false Disable the whole group.

ToggleItem props

Use ToggleItem children for custom content (icons, mixed markup). For plain lists, prefer options.

Props

Prop Type Default Description
value string This item's value (required).
icon ReactNode Optional leading icon.
disabled boolean false Disable just this item.