Skip to content

ButtonGroup

Joins a few buttons that belong together into one object, so they read as one decision: ways to export, previous and next, an action and its variations.

import { ButtonGroup } from '@sypnia/ui/react'

On this page
  1. One kind of action
  2. An action and its variations
  3. Previous and next
  4. When to use it
  5. For everyone
  6. Props

One kind of action

Three ways to export the same table.

Code
import { Button, ButtonGroup } from '@sypnia/ui/react';

export default function Formats() {
  return (
    <ButtonGroup label="Export the table orders">
      <Button icon="download">CSV</Button>
      <Button>JSON</Button>
      <Button>SQL</Button>
    </ButtonGroup>
  );
}

An action and its variations

Press the arrow: the less common ways to run are in a menu.

Code
import { Button, ButtonGroup, IconButton, Menu, MenuItem, toast, Toaster } from '@sypnia/ui/react';

// The main action, and the rarer ones behind the arrow.
export default function WithMenu() {
  return (
    <>
      <ButtonGroup label="Run the query">
        <Button variant="primary" icon="play" onClick={() => toast('Query finished', { detail: '214 rows in 38 ms' })}>Run query</Button>
        <Menu trigger={<IconButton variant="primary" icon="chevron-down" label="More ways to run" tooltip={false} />}>
          <MenuItem onAction={() => toast('Selection finished', { detail: '12 rows in 9 ms' })}>Run the selection only</MenuItem>
          <MenuItem onAction={() => toast('Plan ready')}>Explain the plan</MenuItem>
        </Menu>
      </ButtonGroup>
      <Toaster />
    </>
  );
}

Previous and next

Each end disables its button instead of hiding it, so nothing jumps.

Row 1 of 5
Code
import { useState } from 'react';
import { ButtonGroup, IconButton } from '@sypnia/ui/react';

export default function Stepping() {
  const [row, setRow] = useState(1);
  return (
    <div className="sy-row">
      <ButtonGroup label="Move between rows">
        <IconButton variant="secondary" icon="chevron-left" label="Previous row" disabled={row === 1} onClick={() => setRow(row - 1)} />
        <IconButton variant="secondary" icon="chevron-right" label="Next row" disabled={row === 5} onClick={() => setRow(row + 1)} />
      </ButtonGroup>
      <span className="sy-text--sm sy-num">Row {row} of 5</span>
    </div>
  );
}

When to use it

Use it when

  • Two to four actions of the same kind sit side by side.
  • One action has rarer variations: the main button plus an arrow that opens a Menu.
  • A pair moves through something: previous and next.

Do not use it when

  • The buttons choose a mode or a view that stays selected: that is a SegmentedControl.
  • The actions are unrelated: leave them apart, in a row or in Actions.
  • There are more than four: put the rest in a Menu.

For everyone

  • The group has a name (label) that screen readers say when focus enters it.
  • Each button is still its own Tab stop and works with Enter and Space.
  • The focus ring of a button is drawn above its neighbours, never cut by them.

Props

ButtonGroupTypeDefault
labelrequired string
className string
  1. One kind of action
  2. An action and its variations
  3. Previous and next
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms