Split button
A joined main action and stable chevron menu, with hold-drag alternatives and optional remembered selection.
npx @swipeui/cli add split-buttonWhen 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.tsand 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 installso versions match your SDK.
Usage
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
| Prop | Default | Behavior |
|---|---|---|
label | required | Visible main label before a remembered selection. |
icon | none | Node or render function receiving { color, size }. |
onPress | none | Original main action; caller owns async loading/results. |
actions | required | Unique id, label, optional icon, destructive, disabled, onSelect. Disabled rows remain visible. |
onSelect | none | Reports each chosen id, including remembered main presses. Runs alongside the item's handler once. |
rememberLast | false | Remember the chosen alternative's label, icon and handler. |
value | uncontrolled | Controlled remembered id. Changes display only when the owner updates it. |
defaultValue | none | Initial uncontrolled remembered id. |
onValueChange | none | Reports a new remembered id once; repeated activation of the same id does not report a change. |
menuOnLongPress | true | Open alternatives by holding the main half. The chevron always remains a tap alternative. |
dragToSelect | true | During that hold, drag onto an enabled row and release to run it. False keeps long-press opening with tap selection. |
longPressDelay | 500 | Hold threshold in milliseconds; content timing, independent of motion feel. |
divider | true | Label-colored low-strength hairline between halves. |
chevronMorph | true | Morph down/up with expansion; false swaps endpoints. |
menuWidth | 240 | Preferred menu width, clamped to safe viewport bounds. |
loading | false | Spinner and busy/disabled state on the main half; the chevron and alternatives remain available. |
loadingLabel | current label | Optional visible/spoken pending label. |
loadingPlacement | start | Shared Button spinner placement: start or center. |
disabled | false | Block both halves, drag selection and accessibility actions. |
variant | solid | Button styles: solid, tinted, outline, ghost, plain; legacy aliases work. |
tone | Button default | primary, neutral, destructive, success. A remembered destructive action uses destructive tone. |
size | md | Shared sm / md / lg. The chevron always keeps a 44pt minimum target. |
shape | preset | Preset control corners, or pill. Joined edges stay square. |
block | false | Stretch to container width while reserving the fixed chevron target. |
highlight | true | Shared Button top rim around the joined surface. |
glow | false | Shared Button tone glow under the joined surface. |
pressEffect | both | Main-half both, scale, wash or none. The chevron never scales. |
labelMorph | fade | Shared label behavior; remembered labels reserve the widest label to keep the menu anchor still. |
disabledStyle | muted | Shared muted or dim appearance. |
haptics | true | Boolean or { press, menu, drag }; each omitted switch defaults to true. Opening uses medium impact; crossing an enabled row uses a selection tick. |
motion | inherited | Shared press/morph/overlay/ambient roles. Reduce Motion removes travel and holds the spinner still. |
accessibilityLabel | label | Original main spoken name. Remembered actions speak their current label. |
moreActionsLabel | more actions | Localized suffix after the main name on the chevron. |
className | none | Root classes merged after shared surface classes. |
style | none | Root native style override. |
textClassName | none | Main label classes. |
testID | none | Root 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,overlayandambientmotion roles, so it follows your app's feel. Passmotionto 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 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.