Toggle Group
A set of toggles with single or multiple selection, shared variant and size, joined or spaced.
Preview
Pebble redesign14 tasks · Ines, Malik, Priya
Recessed, single
Raised, multiple
Loose keys
Sizes
Disabled
Install
Add the editable source with the shadcn CLI. Your project also needs the shared theme tokens this component uses. Setup and requirements. The Pebble installer is not published yet.
npx shadcn@latest add https://pebbleui.com/r/toggle-group.jsonProps
| Prop | Type | Default | Description |
|---|---|---|---|
| type | "single" | "multiple" | - | Required. One pressed item at most, or any number. |
| value | string | string[] | - | Controlled value (string for single, array for multiple). |
| defaultValue | string | string[] | - | Initial value when uncontrolled. |
| onValueChange | (value) => void | - | Called when the pressed items change. |
| variant | "default" | "outline" | "default" | Shared with every item; an item's own prop overrides it. |
| size | "sm" | "md" | "lg" | "md" | Shared with every item; an item's own prop overrides it. |
| spacing | number | 0 | Gap between items in spacing units; 0 joins them into one bar. |
| disabled | boolean | false | Disables every item. |
| orientation | "horizontal" | "vertical" | - | Restricts arrow-key navigation to one axis. |
Build notes
Built on the Radix ToggleGroup primitive, which owns selection state, roving
focus and roles. The root provides `{ variant, size, spacing }` through React
context; each item resolves its own prop first, then the group's, then the
toggle defaults, and renders `toggleVariants()` imported from the Toggle item,
so a group item and a standalone toggle are pixel-identical. Spacing is passed
as a CSS variable (`--toggle-group-gap`) and read by
`gap-[--spacing(var(--toggle-group-gap))]`, so any spacing step works without
generating classes. When spacing is 0, items drop their radius except the outer
corners (`first:rounded-s-md last:rounded-e-md`) and outline items remove their
start border except the first; logical `s`/`e` sides mirror under RTL.
Deviations from the source: item props override the group (the source let the
group always win), size keys `sm/md/lg`, logical sides for RTL, joining decided
in JS from context instead of `data-[spacing=0]` selectors. Vertical joined
styling is not provided.
**Pebble (2026-11-03).** Joined groups became a tray the keys sit in rather than a strip of shared borders: the root takes `rounded-lg p-0.5 gap-0.5` plus a raised (`outline`) or recessed (`default`) surface, and items render `toggleVariants({ variant: "default" })` so the tray, not each item, carries the variant. The on item is the Toggle lit key, which makes a single-mode group read as a choice of lit keys; this deliberately differs from Segmented Toggle, whose single raised thumb slides with `layoutId`. Dividers are each non-first item's `::before` (1 px `bg-border`, inset 8 px top and bottom, centred in the 2 px gap) and fade out beside a lit or hovered key via `data-[state=on]:`, `[[data-state=on]+&]:`, `enabled:hover:` and `[:enabled:hover+&]:`. The old `rounded-none` and `border-s-0` joining classes are gone. Loose items are unchanged full Toggles.
<!-- PEBBLE-LICENSE -->View source
registry/button/toggle-group/toggle-group.tsx
"use client";
/* PEBBLE-LICENSE
Built by Pebble. Component: toggle-group.
First-party license: MIT
The following first-party terms apply only to original Pebble material.
MIT License
Copyright (c) 2026 Praxys Solutions LLC (Pebble)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THIRD-PARTY NOTICES
These notices apply to identified upstream portions; Pebble terms do not replace or narrow their rights.
Upstream: https://raw.githubusercontent.com/shadcn-ui/ui/main/LICENSE.md
MIT License
Copyright (c) 2023 shadcn
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
END PEBBLE-LICENSE */
import * as React from "react";
import { ToggleGroup as ToggleGroupPrimitive } from "radix-ui";
import { cn } from "@/lib/utils";
import { toggleVariants, type ToggleStyleProps } from "@/registry/button/toggle/toggle";
type ToggleGroupContextValue = ToggleStyleProps & { spacing: number };
const ToggleGroupContext = React.createContext<ToggleGroupContextValue>({ spacing: 0 });
// Joined groups are one tray the keys sit in. `outline` raises the tray as a
// card pebble; `default` sinks it into the surface as a recessed well.
const trays = {
outline: "bg-card ring-1 ring-hairline shadow-raised-xs inset-shadow-highlight",
default: "bg-muted ring-1 ring-hairline inset-shadow-xs",
} as const;
export type ToggleGroupProps = React.ComponentProps<typeof ToggleGroupPrimitive.Root> &
ToggleStyleProps & {
/** Gap between items in spacing units. 0 joins the items into one tray. */
spacing?: number;
};
export function ToggleGroup({
variant,
size,
spacing = 0,
className,
style,
children,
...props
}: ToggleGroupProps) {
const value = React.useMemo(() => ({ variant, size, spacing }), [variant, size, spacing]);
const joined = spacing === 0;
return (
<ToggleGroupPrimitive.Root
data-slot="toggle-group"
data-variant={variant ?? "default"}
data-size={size ?? "md"}
data-spacing={spacing}
style={{ "--toggle-group-gap": spacing, ...style } as React.CSSProperties}
className={cn(
"group/toggle-group flex w-fit items-center",
joined
? cn(
"gap-0.5 rounded-lg p-0.5 forced-colors:border forced-colors:border-[CanvasText]",
trays[variant ?? "default"],
)
: "gap-[--spacing(var(--toggle-group-gap))]",
className,
)}
{...props}
>
<ToggleGroupContext.Provider value={value}>{children}</ToggleGroupContext.Provider>
</ToggleGroupPrimitive.Root>
);
}
// A hairline between neighbouring keys in a joined tray. It hides beside a
// lit key (on either side) and on hover, so the lit key reads as one object.
const divider = [
"not-first:before:pointer-events-none not-first:before:absolute not-first:before:inset-y-2 not-first:before:-start-[1.5px] not-first:before:w-px not-first:before:bg-border",
"before:transition-opacity before:duration-(--motion-fast) motion-reduce:before:transition-none",
"data-[state=on]:before:opacity-0 [[data-state=on]+&]:before:opacity-0 enabled:hover:before:opacity-0 [:enabled:hover+&]:before:opacity-0",
].join(" ");
export type ToggleGroupItemProps = React.ComponentProps<typeof ToggleGroupPrimitive.Item> &
ToggleStyleProps;
export function ToggleGroupItem({ variant, size, className, ...props }: ToggleGroupItemProps) {
const group = React.useContext(ToggleGroupContext);
// An item's own prop wins, then the group's, then the toggle default.
const resolvedVariant = variant ?? group.variant ?? "default";
const resolvedSize = size ?? group.size ?? "md";
const joined = group.spacing === 0;
return (
<ToggleGroupPrimitive.Item
data-slot="toggle-group-item"
data-variant={resolvedVariant}
data-size={resolvedSize}
data-spacing={group.spacing}
className={cn(
// Inside a joined tray the keys are flat until hovered or lit: the
// tray carries the variant's surface. Loose items are full toggles.
toggleVariants({ variant: joined ? "default" : resolvedVariant, size: resolvedSize }),
joined && "enabled:hover:bg-background/70",
// The wash contrasts with the tray, which is the group's variant.
joined && group.variant === "outline" && "enabled:hover:bg-muted",
joined && divider,
className,
)}
{...props}
/>
);
}
