For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
43
Sponsor

Toggle Group

A set of two-state buttons that can be toggled on or off.

import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";

import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";

Installation

$ pnpm dlx shadcn@latest add https://shadcn-cssinjs.com/r/toggle-group.json

Usage

import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group/toggle-group";
<ToggleGroup multiple>
  <ToggleGroupItem value="bold">B</ToggleGroupItem>
  <ToggleGroupItem value="italic">I</ToggleGroupItem>
</ToggleGroup>

Composition

Use the following composition to build a Toggle Group:

ToggleGroup
├── ToggleGroupItem
└── ToggleGroupItem

Examples

Outline

import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";

export function ToggleGroupOutline() {

Size

import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";

const SIDES = ["top", "bottom", "left", "right"];

Spacing

Use the spacing prop to separate the items.

import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";

const SIDES = ["top", "bottom", "left", "right"];

Vertical

import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";

import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";

Disabled

import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";

import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";

Custom

Use font-normal to set the font weight.

"use client";

import { useState } from "react";

import {
  Field,

RTL

To enable right-to-left support, see the RTL guide.

"use client";

import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";

import { useTranslation } from "@/components/language-selector";
import type { Translations } from "@/components/language-selector";

API Reference

See the Base UI documentation for the full API.