Web and native

ButtonGroup in kanso-ui 0.59.0, for React.

import { ButtonGroup } from '@kanso-labs/kanso-ui'

A row of Buttons and IconButtons drawn as one standard or connected group, which can also keep a selection among them.

It follows the Material Design button groups page. The group draws nothing of its own: it gives each button its size, its corners and its part in the press. In a standard group a pressed button widens by 15% of its width while its neighbours narrow, so the group's width holds; in a connected group the buttons stay put and a pressed one tightens its inner corners while a selected one rounds them off.

What you provide

  • children: Buttons and IconButtons. In a group that selects, give each an id, which is what the selection is reported by.
  • An aria-label or aria-labelledby naming the group.

Props

PropTypeDefaultDescription
childrenReactNode—The buttons: Buttons and IconButtons, each with an `id` in a group that selects.
classNamestring—The class for the group's own element.
disallowEmptySelectionbooleantrue while the group selects one, false while it selects severalWhether the checked button stays checked when it is pressed again. On by default while the group selects one, since a radio group always holds a choice; `false` lets a press clear it, as React Aria's own default does. Off by default while it selects several, where any of them can be turned off.
selectionModeToggleButtonGroupProps['selectionMode']—Makes the group select, as React Aria's `ToggleButtonGroup`: `single` for one at a time, `multiple` for any number. Left out, the group's buttons are plain buttons.
shapeButtonShape'round'The shape a connected group gives its two ends: `round`, the pill, or `square`, the size's corner, which its inner corners take as well.
sizeButtonSize'md'The size every button in the group takes, unless it names its own, and the size the group shapes them for. `xl` and `xxl` are deprecated and render at `lg`, as Button's do. Deprecated sizes. Kanso stops at lg, 56px: xl (96px) and xxl (136px) are deprecated in Kanso, though kanso-ui still accepts them.
styleCSSProperties—The style for the group's own element.
variant'connected' | 'standard''standard'`standard` sets the buttons 8px apart and widens a pressed one; `connected` sets them 2px apart with tighter inner corners.

Also takes the props of Omit<ToggleButtonGroupProps, 'children' | 'className' | 'disallowEmptySelection' | 'selectionMode' | 'style'>.

Example

import { Button, ButtonGroup } from '@kanso-labs/kanso-ui'

<ButtonGroup aria-label="Label" variant="connected" selectionMode="single" defaultSelectedKeys={['second']}>
  <Button id="first" variant="tonal">First item</Button>
  <Button id="second" variant="tonal">Second item</Button>
  <Button id="third" variant="tonal">Third item</Button>
</ButtonGroup>

The design’s classes

k-btngroup, k-btngroup--fill, with k-btn children.

Maps to ButtonGroup in kanso-ui and react-native-kanso-ui.