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-groupVariant
Preset
Material
Scheme
Feel
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.tsxand 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 installso versions match your SDK.
Usage
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
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.
variantdefaults tosoft; 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
selectandpressmotion roles, so it follows your app's feel. Passmotionto 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 on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.