DocsHooks & utilities
Selection core
The selection language every picker, list, chip, segment and slider shares.
The selection language: one option shape, a gliding highlight, drawn checks, option rows, matching, keys, paint-select, press-drag-release, roll direction, presentation and per-part haptics.
Free (MIT)Version 1.1.0Released 8 Nov 2026iOS and Android
When to use it
- Building a list, chip, segment, toggle, radio, slider or calendar that should feel like the rest of the selection family.
- Sharing one option shape (`SelectionOption`) across pickers so options move between components unchanged.
- Adding a gliding highlight, drawn checks, roving keys, type-ahead, paint-select or hold-drag-release to your own control.
When not to use it
- Picking from a list in an app screen: use Select, Combobox or Multi-select, which compose this.
- Long virtualised lists inside a popover: OptionList renders plain rows, so long lists belong in a sheet.
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 selection-core- Adds
components/swipeui/lib/selection-core.ts,components/swipeui/lib/selection-types.ts,components/swipeui/lib/use-selection-highlight.ts,components/swipeui/lib/selection-glyph.tsx,components/swipeui/lib/option-list.tsx,components/swipeui/lib/match-options.ts,components/swipeui/lib/use-roving-keys.ts,components/swipeui/lib/paint-shared.ts,components/swipeui/lib/use-paint-select.ts,components/swipeui/lib/use-paint-select.native.ts,components/swipeui/lib/press-drag-shared.ts,components/swipeui/lib/use-press-drag-release.ts,components/swipeui/lib/use-press-drag-release.native.ts,components/swipeui/lib/use-direction.ts,components/swipeui/lib/presentation.ts,components/swipeui/lib/use-selection-haptics.tsand 11 shared helpers. - Installs react-native-gesture-handler, react-native-reanimated, react-native-svg, react-native-worklets, uniwind, clsx, tailwind-merge, expo-haptics, class-variance-authority. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { OptionList, matchOptions } from '@/components/swipeui/lib/selection-core';
import type { SelectionOption } from '@/components/swipeui/lib/selection-core';
const plans: SelectionOption[] = [
{ value: 'free', label: 'Free', description: 'For trying things out' },
{ value: 'pro', label: 'Pro', badge: 'Popular', detail: '$8' },
{ value: 'team', label: 'Team', disabled: true, disabledReason: 'Coming soon' },
];
<OptionList options={matchOptions(query, plans)} value={[plan]} onPick={setPlan} query={query} />;SelectionOptionis one option shape for every selection item:value,label,description,detail,icon,keywords,disabled,disabledReason,groupandbadge.OptionListdraws plain rows (safe inside a popover) with groups, icons, details, badges, disabled reasons, bold matches, one gliding highlight and checks that draw themselves on. On the web it is one focus stop with arrow keys and type-ahead.useItemFramesanduseSelectionHighlightgive your own control the same highlight: it glides when the chosen item changes and snaps when only the layout moved.matchOptionsandhighlightMatchfold case and accents and rank a prefix first; CJK, Hangul and emoji are matched as typed.usePressDragRelease(hold, drag, release to pick) andusePaintSelect(hold, then drag to turn a run on or off) use a long-press recognizer that follows raw touches on phones and a pan on the web.useDirection,resolvePresentation,useRovingKeys,useTypeaheadanduseSelectionHapticscover roll direction, popover or sheet, keys and per-part haptics.
Behavior and gestures
- OptionList rows press to choose; the highlight glides to the chosen row and the check draws itself on.
- On the web, one focus stop per list: arrows, Home/End and PageUp/PageDown move, Enter and Space choose, letters jump, Escape escapes. Right-to-left layouts swap left and right.
- usePressDragRelease: hold a trigger to open its list, drag over the rows (a tick each) and release to pick; lifting away after dragging cancels.
- usePaintSelect: hold an item, then drag across others to turn a run on or off; the first item decides.
Accessibility
- Single-choice rows are radios and several-choice rows are checkboxes, with checked state; disabled rows speak their reason (or Unavailable) as the hint.
- Group headings are headers; the empty state is a polite live region.
- Every gesture helper has a tap path: tapping rows, or the item's own accessibility actions. Marks are decorative; the row carries the name.
Motion
- Uses the
select,drag,toggleandmorphmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The highlight glides on the select spring when the chosen item changes and snaps when only the layout moved; it stretches on the drag spring while a finger moves it.
- Checks draw on and morph into dashes, and dots spring in, on the toggle role.
- useDirection gives rolling labels their direction (morph or number role in the item).
- Reduce Motion: the highlight jumps, marks fade in without drawing, and the stretch goes.
Performance
- Gesture state stays on the UI thread; JavaScript gets one call per newly entered row or item, never one per frame.
- Each animated style lives in its smallest leaf view.
Notes for AI
- Phones resolve the `.native.ts` gesture files (a long-press recognizer that follows raw touches); the web uses the pan versions.
- Pass options in display order; `orderOptions` groups them. Highlights and keys use the same order.
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.