Skip to Content
zjkm-ui
Components

Toggle Group

A row of toggles, like bold and italic.

Props
<ToggleGroup label="Text format" items={items} />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/toggle-group.json
import { ToggleGroup } from "@/components/toggle-group"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

A row of toggle buttons, like bold, italic and underline. With multiple off, pressing one releases the others, for choices like text alignment.

import { HugeiconsIcon } from "@hugeicons/react";
import { TextBoldIcon, TextItalicIcon } from "@hugeicons/core-free-icons";
import { ToggleGroup } from "@/components/toggle-group";

const items = [
  { value: "bold", label: "Bold", icon: <HugeiconsIcon icon={TextBoldIcon} size={18} /> },
  { value: "italic", label: "Italic", icon: <HugeiconsIcon icon={TextItalicIcon} size={18} /> },
];

export function Toolbar() {
  return <ToggleGroup label="Text format" items={items} onChange={(v) => console.log(v)} />;
}

Props

PropTypeDefaultDescription
labelstringNames the group.
items{ value, label, icon? }[]The buttons. With an icon, the label becomes the accessible name.
multiplebooleantrueAllow several on at once.
defaultValuestring[][]On at the start.
onChange(value: string[]) => voidCalled with every change.
classNamestringClasses for the wrapper.

With reduced motion, buttons change without a transition.

On this page