SwipeUI

Expanding button group

Icon segments where only the selected one shows its label and the rest make room, with Button group's gliding highlight and slide-to-choose.

npx @swipeui/cli add expanding-button-group
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When to use it

  • Compact icon toolbars where the selected tool shows its name, such as Pen, Highlighter and Eraser.
  • Filters or view modes in tight headers where labels would crowd.
  • Playful selectors that reveal context only for the active choice.

When not to use it

  • When every label should always be visible. Use Button group or Segmented control.
  • Unrelated actions; a group implies one choice.

Installation

Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.

npx @swipeui/cli add expanding-button-group
  • Adds components/swipeui/ui/expanding-button-group.tsx and 17 shared helpers.
  • Installs react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, react-native-gesture-handler, react-native-safe-area-context, @expo/ui, @gorhom/bottom-sheet, expo-blur, react-native-svg. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/library.tsx
import { ExpandingButtonGroup } from '@/components/swipeui/ui/expanding-button-group';
import { Grid, List, Rows } from '@/components/icons'; // any SVG icon set

<ExpandingButtonGroup
  accessibilityLabel="Layout"
  value={layout}
  onValueChange={setLayout}
  options={[
    { value: 'list', label: 'List', icon: List },
    { value: 'grid', label: 'Grid', icon: Grid },
    { value: 'board', label: 'Board', icon: Rows },
  ]}
/>;

API reference

ExpandingButtonGroupProps

PropTypeDefaultDescription
optionsreadonly ButtonGroupOption<T>[]—

Segments in reading order.

value?T—

Selected segment; passing any selection prop makes it a selection group.

defaultValue?Tthe first enabled segment, in selection mode

Initial selection.

onValueChange?((value: T) => void)—

Reports a newly selected segment.

variant?ButtonGroupLegacyVariant | ButtonGroupVariant'outline'

The surface: outline, soft, tinted or solid. The 1.x names joined, tray and expanding still work.

size?ButtonGroupSize'md'
shape?ButtonGroupShape'preset'
orientation?"horizontal" | "vertical"'horizontal'

A row, or a column (such as zoom controls on a canvas).

layout?ButtonGroupLayout'fit'
iconOnly?booleanfalse

Shows only icons for segments that have one.

dividers?booleantrue

Hairlines between segments, which fade beside the highlight.

highlight?booleantrue

The shared highlight that glides to the pressed (or selected) segment.

slideToSelect?booleantrue

Slide a finger across the group to move the highlight, and release to choose.

menu?ButtonGroupMenu—

A trailing chevron segment that opens more actions.

confirmDuration?number1600

How long a confirmLabel stays before the label returns, in milliseconds.

disabled?booleanfalse

Disables every segment and the menu.

haptics?ButtonGroupHapticstrue

Feedback on press and ticks while sliding; pass an object to switch them separately.

motion?MotionOverridethe app's feel (`smooth` without a provider)

The app's motion feel, or a local override.

accessibilityLabel?string—

Names the group for screen readers.

className?string—

Classes for the tray.

style?StyleProp<ViewStyle>—

Style escape hatch for the tray.

testID?string—

Root identifier; segments append -<value>, the menu -menu.

Composition and behavior

  • It is Button group with expandSelected: a selection group whose unselected segments shrink to icons while the selected one shows its label and springs wider.
  • Tap an icon, or slide across and lift, to choose; the highlight glides to it with a selection tick.
  • Every segment keeps its label as its spoken name, and the group is announced as a tab list.
  • variant defaults to soft; size, shape, haptics and motion work as in Button group.

Behavior and gestures

  • Tap or slide to an icon and it becomes selected: its label appears and the segment springs wider while the others shrink to icons.
  • The shared highlight glides under the selection with a selection tick.
  • It is Button group with expandSelected, so variant, size, shape, haptics and motion work the same; variant defaults to soft.

Accessibility

  • Every option keeps its name, even when only the icon shows.
  • It's a tab list with selected states, like Button group.
  • Name the group with accessibilityLabel.

Motion

  • Uses the select and press motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Labels expand and collapse with the layout spring.
  • Reduce Motion shows and hides labels instantly.

Performance

  • A thin preset of Button group with the same cost.

Notes for AI

  • Give every option an icon and a label.

Compatibility

Runs onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items