SwipeUI

Split button

A joined main action and stable chevron menu, with hold-drag alternatives and optional remembered selection.

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

  • One action is the usual choice and a short menu offers closely related alternatives.
  • People repeat their preferred export or merge method.

When not to use it

  • All choices have equal priority; use Menu or Button group.
  • A destructive operation needs confirmation; compose a separate confirmation step.

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 split-button
  • Adds components/swipeui/ui/split-button.tsx, components/swipeui/ui/use-split-button.ts, components/swipeui/ui/use-split-button.native.ts and 16 shared helpers.
  • Installs react-native-gesture-handler, react-native-reanimated, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority, 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/export.tsx
import { SplitButton } from '@/components/swipeui/ui/split-button';

<SplitButton
  label="Export file"
  onPress={exportDefault}
  rememberLast
  actions={[
    { id: 'pdf', label: 'Export PDF', onSelect: exportPDF },
    { id: 'image', label: 'Export image', onSelect: exportImage },
  ]}
/>;

Use OverlayProvider inside your safe-area and gesture roots. The styles, remember and states boards use the same specimen in the app and web preview. The remember board puts its switches outside the control; the states board lets you compare a busy main action with an available menu.

Settings

PropDefaultBehavior
labelrequiredVisible main label before a remembered selection.
iconnoneNode or render function receiving { color, size }.
onPressnoneOriginal main action; caller owns async loading/results.
actionsrequiredUnique id, label, optional icon, destructive, disabled, onSelect. Disabled rows remain visible.
onSelectnoneReports each chosen id, including remembered main presses. Runs alongside the item's handler once.
rememberLastfalseRemember the chosen alternative's label, icon and handler.
valueuncontrolledControlled remembered id. Changes display only when the owner updates it.
defaultValuenoneInitial uncontrolled remembered id.
onValueChangenoneReports a new remembered id once; repeated activation of the same id does not report a change.
menuOnLongPresstrueOpen alternatives by holding the main half. The chevron always remains a tap alternative.
dragToSelecttrueDuring that hold, drag onto an enabled row and release to run it. False keeps long-press opening with tap selection.
longPressDelay500Hold threshold in milliseconds; content timing, independent of motion feel.
dividertrueLabel-colored low-strength hairline between halves.
chevronMorphtrueMorph down/up with expansion; false swaps endpoints.
menuWidth240Preferred menu width, clamped to safe viewport bounds.
loadingfalseSpinner and busy/disabled state on the main half; the chevron and alternatives remain available.
loadingLabelcurrent labelOptional visible/spoken pending label.
loadingPlacementstartShared Button spinner placement: start or center.
disabledfalseBlock both halves, drag selection and accessibility actions.
variantsolidButton styles: solid, tinted, outline, ghost, plain; legacy aliases work.
toneButton defaultprimary, neutral, destructive, success. A remembered destructive action uses destructive tone.
sizemdShared sm / md / lg. The chevron always keeps a 44pt minimum target.
shapepresetPreset control corners, or pill. Joined edges stay square.
blockfalseStretch to container width while reserving the fixed chevron target.
highlighttrueShared Button top rim around the joined surface.
glowfalseShared Button tone glow under the joined surface.
pressEffectbothMain-half both, scale, wash or none. The chevron never scales.
labelMorphfadeShared label behavior; remembered labels reserve the widest label to keep the menu anchor still.
disabledStylemutedShared muted or dim appearance.
hapticstrueBoolean or { press, menu, drag }; each omitted switch defaults to true. Opening uses medium impact; crossing an enabled row uses a selection tick.
motioninheritedShared press/morph/overlay/ambient roles. Reduce Motion removes travel and holds the spinner still.
accessibilityLabellabelOriginal main spoken name. Remembered actions speak their current label.
moreActionsLabelmore actionsLocalized suffix after the main name on the chevron.
classNamenoneRoot classes merged after shared surface classes.
stylenoneRoot native style override.
textClassNamenoneMain label classes.
testIDnoneRoot id; parts append -main, -menu-trigger, -chevron, -divider; action rows append -menu-<id>.

Composition and behavior

The original main action and alternatives are separate operations. Selecting an alternative calls its onSelect() and the component's onSelect(id). With rememberLast, subsequent main presses run that alternative. Keep confirmation and async error handling in the caller; pass loading while the main action is busy.

Enabled alternatives are also accessibility actions on the main half. The menu offers ordinary tap targets and keyboard activation, reports expansion and restores focus after dismissal. A remembered action that becomes disabled stays visible and inert; an id removed from the list falls back to the original action.

The JavaScript menu stays in the gesture's native window from opening through release, retaining its modal focus and dismissal behavior without remounting the surface. It uses placed, clipped window frames so screen edges, scrolling and RTL do not rely on guessed row heights. Lifting outside any enabled row does not run an action; the menu remains available for tapping. Cancelling never commits a row.

Native hold arbitration, VoiceOver/TalkBack, Dynamic Type, RTL layout and recordings remain pending founder review. Browser and unit checks do not establish native runtime compatibility.

Behavior and gestures

  • Press the main half to run its action; press the named chevron to open alternatives.
  • Long press the main half to open; drag onto an enabled item and release to choose. Entering a new row gives one selection tick.
  • rememberLast updates the main label, icon and handler. value/defaultValue/onValueChange control memory independently of activation.
  • Loading blocks only the main action. Alternatives remain available. Disabled blocks every activation path.

Accessibility

  • Two named buttons; the chevron reports expanded, and the main half reports busy and disabled.
  • Enabled alternatives are accessibility actions on the main half, alongside the tap menu.
  • Touch targets are at least 44pt. Remembered labels reserve their widest width and use single-line clipping.
  • Native VoiceOver, TalkBack, large Dynamic Type and hold gesture arbitration remain pending founder review.

Motion

  • Uses the press, morph, overlay and ambient motion roles, so it follows your app's feel. Pass motion to tune this one instance.
  • Composes Button press wash, label/icon morphs, main-only ring spinner and the IconMorph down/up chevron.
  • The menu trigger never scales. During a held drag the panel uses a still presentation in the same native window.
  • Reduce Motion removes press scale and geometric travel, keeping brief fades and direct finger selection.

Performance

  • Drag hit-testing runs in a worklet. React updates only when crossing rows or starting/ending a hold.
  • Shared frames are written from JavaScript and read only by UI-thread gestures; no immediate JavaScript readback.
  • All gesture callbacks ignore queued work after unmount; async operations and loading state belong to the caller.
  • The main gesture detector and callbacks remain stable while opening, measuring and hovering the menu, preventing mid-hold native recognizer reconfiguration. Changed caller props and remembered selections still update the main action.
  • Expo/React Native resolve the native hook: a long-press recognizer follows raw touch moves after activation and remains active beyond the button bounds. Web retains the original pan implementation.

Notes for AI

  • Wrap the app in OverlayProvider inside SafeAreaProvider and GestureHandlerRootView.
  • Give actions unique ids. A remembered disabled action stays visible but cannot run; missing ids fall back to the original main action.
  • Each action handler and onSelect fire once per activation; onValueChange fires only when remembered selection changes.
  • Native cross-overlay hold-drag must be reviewed on a phone before release; browser or unit evidence does not close it.

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