SwipeUI

Button group

Related actions joined on one surface: a shared highlight glides under your finger (slide across to pick), hairlines fade beside it, labels confirm in place without shifting the row, and a chevron opens more actions.

npx @swipeui/cli add 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

  • A row of related actions on one item, such as Share, Duplicate and Archive, with the rest in a trailing menu.
  • Compact controls with a live value between them, such as zoom out, 100% and zoom in.
  • A short segmented choice, such as Day, Week and Month, by passing value and onValueChange.
  • A vertical tool rail or zoom rail beside a canvas or map (orientation="vertical").

When not to use it

  • Unrelated actions or a form's main and secondary actions. Space ordinary Buttons apart.
  • A setting that switches the content below as a page-level control. Segmented control is the standard choice.
  • Many options or long labels. Use Select or Menu.
  • One main action with a few alternatives. Split button keeps the main action prominent.

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 button-group
  • Adds components/swipeui/ui/button-group.tsx, components/swipeui/ui/use-button-group.ts and 16 shared helpers.
  • Installs class-variance-authority, react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, 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/document.tsx
import { ButtonGroup } from '@/components/swipeui/ui/button-group';
import { Archive, Copy, Link } from '@/components/icons'; // any SVG icon set

<ButtonGroup
  accessibilityLabel="Document actions"
  options={[
    { value: 'share', label: 'Share', icon: Link, confirmLabel: 'Copied', onPress: copyLink },
    { value: 'duplicate', label: 'Duplicate', icon: Copy, onPress: duplicate },
    { value: 'archive', label: 'Archive', icon: Archive, onPress: archive },
  ]}
  menu={{
    label: 'More actions',
    actions: [
      { id: 'pin', label: 'Pin to sidebar' },
      { id: 'delete', label: 'Delete copy', destructive: true },
    ],
    onSelect: runAction,
  }}
/>;

Icons are components or render functions; each gets { color, size } for the group's surface and size.

Examples

app/canvas.tsx
import { Text } from '@/components/swipeui/ui/text';
import { ButtonGroup } from '@/components/swipeui/ui/button-group';

// A live value between two icon buttons. The middle segment is a display, not a button.
<ButtonGroup
  size="sm"
  accessibilityLabel="Zoom"
  options={[
    { value: 'out', label: 'Zoom out', icon: Minus, iconOnly: true, onPress: zoomOut },
    { value: 'level', label: `Zoom ${zoom}%`, content: <Text>{zoom}%</Text> },
    { value: 'in', label: 'Zoom in', icon: Plus, iconOnly: true, onPress: zoomIn },
  ]}
/>;
app/insights.tsx
// A segmented choice: pass value and onValueChange and the highlight stays under the choice.
<ButtonGroup
  variant="soft"
  layout="fill"
  accessibilityLabel="Range"
  value={range}
  onValueChange={setRange}
  options={[
    { value: 'day', label: 'Day' },
    { value: 'week', label: 'Week' },
    { value: 'month', label: 'Month' },
  ]}
/>
app/editor.tsx
// The main pair of a screen, as a filled capsule. reserveLabels keeps Save as wide as Saved.
<ButtonGroup
  variant="solid"
  shape="pill"
  accessibilityLabel="Draft"
  options={[
    {
      value: 'save',
      label: saved ? 'Saved' : 'Save',
      reserveLabels: ['Save', 'Saved'],
      onPress: save,
    },
    { value: 'preview', label: 'Preview', onPress: preview },
  ]}
/>

API reference

ButtonGroupProps

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.

expandSelected?booleanfalse

In a selection group, only the selected segment shows its label and the others shrink to icons.

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.

ButtonGroupOption

PropTypeDefaultDescription
valueT—

Stable identifier; also the selected value in selection mode.

labelstring—

Visible and spoken name. Icon-only segments keep it as their accessibility label.

icon?ButtonIcon—

Leading icon: a node, or a function that receives { color, size }.

iconOnly?booleanthe group's `iconOnly`

Shows only the icon; the label stays the spoken name.

content?ReactNode—

Replaces the label with live content, such as a zoom level. Without onPress it is display-only.

onPress?(() => void)—

Runs on every activation, including the selected segment.

destructive?booleanfalse

Draws the label and icon in the destructive colour.

confirmLabel?string—

A label shown briefly after a press, such as "Copied", then the label returns.

confirmIcon?ButtonIcon—

An icon shown with confirmLabel.

confirmTone?ButtonGroupConfirmTone'success'

The colour of the confirmation's label and icon: success (green), warning (your preset's warning colour, amber or orange), destructive, primary, or none to keep the label colour.

reserveLabels?readonly string[]—

Other labels this segment can show; it keeps the width of the widest so the row never shifts.

menu?readonly MenuAction[]—

Turns the segment into a menu trigger with a chevron.

menuEngine?MenuEngine'javascript'

Menu engine for this segment.

onMenuSelect?((id: string) => void)—

Reports a chosen menu action.

disabled?boolean—

Prevents activation; the segment dims and is announced as disabled.

ButtonGroupMenu

PropTypeDefaultDescription
labelstring—

Spoken name of the chevron and the menu heading.

actionsreadonly MenuAction[]—

The actions; each can have an icon and be destructive or disabled.

onSelect(id: string) => void—

Reports the chosen action.

engine?MenuEngine'javascript'

Menu engine; native menus draw a text trigger.

width?number240

Menu width in points, kept inside the screen.

Composition and behavior

  • One highlight for the whole group. Touch a segment and it lands under it, growing slightly into place. Slide your finger across and it glides from segment to segment with a selection tick; lift and the segment under your finger runs. In an action group it fades once you lift; in a selection group it stays under the choice.
  • Hairlines sit between segments and fade on both sides of the highlight, so it reads as one shape.
  • Confirmations (confirmLabel, confirmIcon) replace the label for confirmDuration in the confirmTone colour (green by default), then the label returns. The segment keeps the width of its widest label, so nothing beside it moves; screen readers hear the confirmation once.
  • More actions go in menu, a trailing chevron that turns over while its menu is open. The menu is a compact list just under the bar, lined up with its end edge, with no title or close button. A segment with menu opens one from its own label. Rows can have icons and be destructive or disabled.
  • Surfaces: outline (a bordered card, the default), soft (a muted tray), tinted (a wash of your primary colour) and solid (filled, for a screen's main pair). The 1.x names still work.
  • Sizes and shapes: segments are 36, 40 or 44 points tall in a 4-point tray, with corners from your preset (or shape="pill") and a concentric highlight. orientation="vertical" stacks them into a rail.
  • Selection: passing value, defaultValue or onValueChange turns it into a tab list. expandSelected shows only the selected label; Expanding button group is that preset.

Button group settings

PropDoesDefault
variantoutline, soft, tinted or solidoutline
sizesm, md or lgmd
shapepreset (your control radius) or pillpreset
orientationhorizontal or verticalhorizontal
layoutfit (sized to content) or fill (equal widths)fit
iconOnlyIcons only, labels spokenfalse
dividersHairlines between segmentstrue
highlightThe shared gliding highlighttrue
slideToSelectSlide across, lift to runtrue
expandSelectedOnly the selected segment shows its labelfalse
menuA trailing chevron with more actionsnone
confirmDurationHow long a confirmation shows, in ms1600
hapticstrue, false or { press, slide }true
disabledDisables every segment and the menufalse
value / defaultValue / onValueChangeSelection modenone
motionA local motion feel or overridethe app's feel

Per segment: icon, iconOnly, content, onPress, destructive, confirmLabel, confirmIcon, confirmTone (success by default), reserveLabels, menu, menuEngine, onMenuSelect and disabled. When the row is wider than its container, labelled segments shrink and truncate so the chevron stays inside the bar.

Behavior and gestures

  • Touch a segment and one shared highlight lands under it; lift and it fades in an action group, or stays under the choice in a selection group.
  • Slide a finger across the group and the highlight follows from segment to segment with a selection tick; lifting runs (or selects) the segment under the finger; in an expanding group the label opens under the finger as you slide. A plain tap never moves the highlight back. slideToSelect turns sliding off.
  • The hairlines on either side of the highlight fade so it reads as one shape; dividers={false} removes them and highlight={false} removes the highlight.
  • A segment with confirmLabel (and confirmIcon) shows it, such as "Copied", in the confirmTone colour (green by default; warning, destructive, primary or none) for confirmDuration, then returns; reserveLabels keeps the segment as wide as its widest label so the row never shifts.
  • The menu prop adds a trailing chevron that turns over and opens a compact menu just under the bar, lined up with the bar's end edge (icons, destructive and disabled rows, no title or close button); a segment with menu does the same with its label.
  • content puts a live value in a segment, such as a zoom level; without onPress it is a display, not a button.
  • iconOnly (group or segment) shows just icons; expandSelected shows only the selected segment's label while the others shrink to icons.
  • Pressing a segment dips its content on the press spring (icon-only segments dip deeper); the group and its neighbours never move.
  • haptics plays an impact on press and ticks while sliding; pass { press, slide } to switch them separately.
  • When a row is wider than its container, labelled segments shrink and truncate so the chevron and icon-only segments always stay inside the bar.

Accessibility

  • An action group is a toolbar of buttons; with a selection prop it becomes a tab list whose tabs report their selected state.
  • Name the group with accessibilityLabel. Icon-only and content segments keep their label as the spoken name.
  • A confirmation such as "Copied" is announced once and becomes the segment's name while it shows.
  • The chevron is a button named by menu.label that reports expanded; its menu moves focus to its heading and returns it on close.
  • Disabled segments are announced as disabled and dim; sliding skips them and display-only segments.
  • Highlight and dividers use physical positions in a left-to-right layer, so right-to-left layouts mirror correctly; segments still read in reading order.

Motion

  • Uses the select, press, morph and toggle motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Select: the highlight glides between segments; when it first appears it lands in place, growing from 94%, instead of sliding in. It deepens while pressed and fades on lift in an action group.
  • Press: segment content dips on your feel's press scale, deeper for icon-only segments.
  • Morph: confirmation labels rise in as the old label fades; expanding segments resize on the morph spring.
  • Toggle: the chevron turns over while its menu is open.
  • Reduce Motion moves the highlight without travel or growth, cross-fades labels and stops the chevron turning; the press dip is removed.

Performance

  • The highlight, dividers and slide run on the UI thread with shared values; React renders only when the selection, a confirmation or the menu changes.
  • Segment frames are measured once per layout; rebuilding options each render is fine.

Notes for AI

  • Give every segment a unique value and a label, even icon-only ones; name the group with accessibilityLabel.
  • Use onPress per segment for actions; add value and onValueChange only when one segment should stay chosen.
  • Put three or four segments in a group and the rest in menu; use confirmLabel for quick feedback such as Copied.
  • Pass icons as render functions so they get the right colour and size: icon: ({ color, size }) => <Share color={color} size={size} />.

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