Buttons

ToggleButtonGroup

Groups multiple ToggleButtons into a unified control, allowing users to select one or multiple options.

Completeness: behavior-required

The stylesheet is only the visible half of this component. It also needs a keyboard map, focus managed across more than one element, ARIA attributes that point at other nodes, and [data-*] attributes that only running code sets — so a CSS-only port will not reproduce it. Use @blakeui/react, or read the interaction contract from the MCP server with get_component_behavior("ToggleButtonGroup") and build the behaviour yourself.

Import

import { ToggleButtonGroup, ToggleButton } from '@blakeui/react';

Usage

import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";

export function Basic() {
  return (

Anatomy

Import the ToggleButtonGroup component and access all parts using dot notation.

import { ToggleButtonGroup, ToggleButton } from '@blakeui/react';

export default () => (
  <ToggleButtonGroup selectionMode="multiple">
    <ToggleButton id="first">First</ToggleButton>
    <ToggleButton id="second">
      <ToggleButtonGroup.Separator />
      Second
    </ToggleButton>
    <ToggleButton id="third">
      <ToggleButtonGroup.Separator />
      Third
    </ToggleButton>
  </ToggleButtonGroup>
);

Sizes

Small
Medium (default)
Large
import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";

export function Sizes() {
  return (

Orientation

Horizontal
Vertical
import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {Bold, Italic, Underline} from "@gravity-ui/icons";

export function Orientation() {
  return (

Detached

Use isDetached to separate buttons with gaps instead of connecting them.

Attached (default)
Detached
import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";

export function Attached() {
  return (

Full Width

import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {
  Bold,
  Italic,
  Strikethrough,

Selection Mode

Use selectionMode="single" for mutually exclusive choices or selectionMode="multiple" for independent toggles.

Single selection
Multiple selection
import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {
  Bold,
  Italic,
  Strikethrough,

Controlled

Selected: bold

"use client";

import type {Key} from "@blakeui/react";

import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";

Disabled

All buttons disabled
Individual button disabled
import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {Bold, Italic, Underline} from "@gravity-ui/icons";

export function Disabled() {
  return (

Without Separator

Simply omit the <ToggleButtonGroup.Separator /> component from your buttons.

import {ToggleButton, ToggleButtonGroup} from "@blakeui/react";
import {Bold, Italic, Strikethrough, Underline} from "@gravity-ui/icons";

export function WithoutSeparator() {
  return (

Styling

Passing Tailwind CSS classes

import { ToggleButtonGroup, ToggleButton } from '@blakeui/react';

function CustomToggleButtonGroup() {
  return (
    <ToggleButtonGroup className="bg-purple-100" selectionMode="single">
      <ToggleButton id="a">Option A</ToggleButton>
      <ToggleButton id="b">
        <ToggleButtonGroup.Separator />
        Option B
      </ToggleButton>
    </ToggleButtonGroup>
  );
}

Customizing the component classes

To customize the ToggleButtonGroup component classes, you can use the @layer components directive.
Learn more.

A worked example is in Styling.

blakeUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.

CSS Classes

The ToggleButtonGroup component uses these CSS classes (View source styles):

Base & Layout Classes

  • .toggle-button-group - Base container styles
  • .toggle-button-group--horizontal - Horizontal orientation
  • .toggle-button-group--vertical - Vertical orientation
  • .toggle-button-group--full-width - Full width modifier
  • .toggle-button-group__separator - Separator element between buttons

Modifier Classes

  • .toggle-button-group--detached - Detached mode (separated buttons with gaps)

API Reference

ToggleButtonGroup Props

Inherits from React Aria ToggleButtonGroup.

PropTypeDefaultDescription
selectionMode"single" | "multiple""single"Whether one or multiple buttons can be selected
selectedKeysIterable<Key>-Controlled selection state
defaultSelectedKeysIterable<Key>-Default selected keys (uncontrolled)
onSelectionChange(keys: Set<Key>) => void-Called when selection changes
disallowEmptySelectionbooleanfalsePrevents clearing all selections
orientation"horizontal" | "vertical""horizontal"Layout direction
size"sm" | "md" | "lg""md"Size propagated to child ToggleButtons
isDetachedbooleanfalseWhether buttons are visually separated with gaps
fullWidthbooleanfalseWhether the group fills available width
isDisabledbooleanfalseDisables all buttons in the group
classNamestring-Additional CSS classes

ToggleButtonGroup.Separator Props

PropTypeDefaultDescription
classNamestring-Additional CSS classes

Notes

  • ToggleButtonGroup uses React Context to pass size to all child ToggleButton components
  • Each ToggleButton must have a unique id prop that corresponds to the keys used in selectedKeys / defaultSelectedKeys
  • The isDisabled prop is handled natively by React Aria and disables all child ToggleButtons — individual buttons can override this by setting isDisabled={false}
  • The component automatically handles border radius between buttons
  • Add <ToggleButtonGroup.Separator /> inside each ToggleButton (except the first) to show dividers between buttons
  • Use disallowEmptySelection with selectionMode="single" to ensure one option is always selected

On this page