Componentform0.9 KB gzipZero dependencies
Toggle Group
Single-choice segmented control with roving tabindex.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add toggle-groupOr install the full npm package:
npm install bigbulluiUsage
tsx7 lines
import { ToggleGroup, ToggleItem } from "@/components/ui/toggle-group"; <ToggleGroup defaultValue="all"> <ToggleItem value="all">All</ToggleItem> <ToggleItem value="stubs">Stubs</ToggleItem> <ToggleItem value="vip">VIP</ToggleItem></ToggleGroup>Source code
toggle-group.tsx + 1 helperZero third-party dependencies (2 local files shown in tabs below).
tsxtoggle-group.tsx130 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; interface ToggleGroupContextValue { value?: string; onSelect: (val: string) => void;} const ToggleGroupCtx = React.createContext<ToggleGroupContextValue | null>(null); export interface ToggleGroupProps extends React.HTMLAttributes<HTMLDivElement> { value?: string; defaultValue?: string; onValueChange?: (value: string) => void; children?: React.ReactNode; className?: string;Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { ToggleGroup } from "@/components/ui/toggle-group"; <ToggleGroup />| Prop | Type | Description |
|---|---|---|
| value | string | Controlled value. |
| defaultValue | string | Initial value when uncontrolled. (Default: "") |
| onValueChange | (value: string) => void | Callback invoked on value change. |
| children | React.ReactNode | Child elements rendered inside the component. |
| className | string | Optional Tailwind or custom CSS classes merged with component styles. |
| aria-label | string | Configures aria label. |