EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
ToggleButton·component·@astryxdesign/core

Toggle Button Group

Groups toggle buttons for exclusive (single) or multi-select behavior. Uses discriminated union on type for type-safe value/onChange.

Open in Playground @astryxdesign/core/ToggleButton

Showcases and examples

3 documented examples

Toggle Button Group

ToggleButtonGroup manages a set of ToggleButtons with single-select or multi-select behavior for options like view modes or filters.

Preview loads on approachPreview loads on approach
Exact source · toggle-button-group-showcase
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {useState} from 'react';
import {ToggleButton, ToggleButtonGroup} from '@astryxdesign/core/ToggleButton';
import {VStack} from '@astryxdesign/core/Layout';
import {Text} from '@astryxdesign/core/Text';

export default function ToggleButtonGroupShowcase() {
  const [view, setView] = useState<string | null>('grid');
  const [filters, setFilters] = useState<string[]>(['active']);

  return (
    <VStack gap={4}>
      <VStack gap={1}>
        <Text type="label" color="secondary">
          Single select
        </Text>
        <ToggleButtonGroup value={view} onChange={setView} label="View mode">
          <ToggleButton value="list" label="List" />
          <ToggleButton value="grid" label="Grid" />
          <ToggleButton value="board" label="Board" />
        </ToggleButtonGroup>
      </VStack>
      <VStack gap={1}>
        <Text type="label" color="secondary">
          Multi select
        </Text>
        <ToggleButtonGroup
          type="multiple"
          value={filters}
          onChange={setFilters}
          label="Status filters">
          <ToggleButton value="active" label="Active" />
          <ToggleButton value="pending" label="Pending" />
          <ToggleButton value="closed" label="Closed" />
        </ToggleButtonGroup>
      </VStack>
    </VStack>
  );
}

Usage

Groups toggle buttons for exclusive (single) or multi-select behavior. Uses discriminated union on type for type-safe value/onChange.

Typed props

PropType and behavior
childrenReactNode · required
ToggleButton children. Give each member a value; the group owns its pressed state and ignores its isPressed, onPressedChange, and pressedChangeAction props. Member activation calls the group’s onChange without starting a member Action transition.
labelstring · required
Accessible label for the group (aria-label).
type'single' | 'multiple' · default 'single'
Selection mode. Single allows one active button, multiple allows many.
valuestring | null | string[] · required
Currently selected value(s). Type depends on selection mode.
onChange(value: string | null | string[]) => void · required
Called when selection changes.
orientation'horizontal' | 'vertical' · default 'horizontal'
Layout direction of the button group.
size'sm' | 'md' | 'lg' · default 'md'
Default size for buttons in the group. Individual buttons can override.
isDisabledboolean · default false
Whether all buttons in the group are disabled.
xstyleStyleXStyles
StyleX styles for layout customization (margins, positioning, sizing). Must be a stylex.create() value.
data-testidstring
Test selector for automated testing frameworks.