Skip to content

The open alternative to Salesforce, designed for AI.

4.2 KB
Raw Blame
---
title: ButtonGroup
description: Group related buttons with shared appearance and an optional frame.
---

import { PageBanner } from "/snippets/page-banner.mdx"

import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import ButtonGroupReference from '/snippets/ui/generated/input/button-group.mdx';

## Overview

Give a group an accessible name and place related buttons inside it. The group joins adjacent borders and can apply defaults for size, variant, and color. Buttons retain their own tab stops.

<StoryEmbed
  storyId="ui-input-button-buttongroup--display"
  title="Button group"
  height={100}
/>

## Usage

```tsx
import { IconCheckbox, IconNotes, IconTimelineEvent } from 'twenty-ui/icon';
import { Button, ButtonGroup } from 'twenty-ui/primitives/input';

export const ActivityActions = () => (
  <ButtonGroup aria-label="Create activity" size="sm">
    <Button startIcon={<IconNotes />}>Note</Button>
    <Button startIcon={<IconCheckbox />}>Task</Button>
    <Button startIcon={<IconTimelineEvent />}>Activity</Button>
  </ButtonGroup>
);
```

## State ownership

`ButtonGroup` coordinates appearance, not selection. It has no controlled or uncontrolled selection mode. Each button receives its own action handler and application state; see [Button's state ownership example](/ui/primitives/input/button#state-ownership) for loading behavior.

For a mutually exclusive choice, use [RadioGroup](/ui/primitives/input/radio-group), which owns selection for its radio controls.

## Appearance precedence

Each appearance prop resolves independently: the child's explicit prop, then the group default, then the component default. This applies to both Button and IconButton, including an explicit `IconButton size="xs"`. Defaults reach children through fragments, wrappers, and tooltip anchors.

A group can supply `color="inherit"` on a colored surface. A child that resolves to inherited color must also resolve to a non-solid variant. Explicit child color and variant overrides take precedence, so a child may choose a non-solid variant or a semantic color when the group supplies solid and inherit together.

Keep attached buttons at the same size so their edges align. This example overrides variant and color while inheriting the group size.

```tsx
import { Button, ButtonGroup } from 'twenty-ui/primitives/input';

export const ActivityActions = () => (
  <ButtonGroup
    aria-label="Activity actions"
    variant="solid"
    color="accent"
    size="sm"
  >
    <Button variant="ghost" color="danger">
      Delete activity
    </Button>
    <Button color="neutral">Duplicate activity</Button>
    <Button>New activity</Button>
  </ButtonGroup>
);
```

<StoryEmbed
  storyId="ui-input-button-buttongroup--appearance-overrides"
  title="Individual appearance in a button group"
  height={100}
/>

## Detached controls

Set `attached={false}` to keep each control's rounded corners and a 2px gap. Group defaults still apply through wrappers and tooltip anchors; explicit child props take precedence.

## Framed controls

Set `framed` to add a translucent background, border, 2px padding, and concentric corners. The frame works with attached or detached controls and preserves explicit child appearance. Use `size="xs"` on [IconButton](/ui/components/input/icon-button) for compact 20px actions.

<StoryEmbed
  storyId="ui-components-iconbutton--framed-group-documentation"
  title="Framed button group"
  height={100}
/>

```tsx
import { IconButton } from 'twenty-ui/components/input';
import { IconPlus, IconTrash } from 'twenty-ui/icon';
import { ButtonGroup } from 'twenty-ui/primitives/input';

export const CompactRecordActions = () => (
  <ButtonGroup framed attached={false} aria-label="Record actions">
    <IconButton size="xs" aria-label="Add" variant="ghost">
      <IconPlus />
    </IconButton>
    <IconButton size="xs" aria-label="Delete" variant="ghost" disabled>
      <IconTrash />
    </IconButton>
  </ButtonGroup>
);
```

## Updating existing groups

Replace `IconButtonGroup` and its `iconButtons` array with `ButtonGroup framed attached={false}` and explicit children. Replace `InsideButton` with `LightIconButton size="xs"`. Each button owns its accessible name, action handler, disabled state, and optional tooltip.

## Props

<ButtonGroupReference />

<PageBanner illustration="page-cover-pointer" />