Toggle group
Connected state choices for editing tools, layouts and filters.
npx @swipeui/cli add toggle-groupWhen to use it
- Representing persistent formatting, layout or filter state.
When not to use it
- Triggering an action; use ButtonGroup.
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 toggle-group- Adds
components/swipeui/ui/toggle-group.tsx,components/swipeui/ui/use-toggle-group.tsand 15 shared helpers. - Installs react-native-reanimated, react-native-gesture-handler, uniwind, clsx, tailwind-merge, react-native-worklets, expo-haptics, class-variance-authority, react-native-svg, react-native-safe-area-context. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { ToggleGroup } from '@/components/swipeui/ui/toggle-group';
<ToggleGroup type="multiple" options={[{value:'bold',label:'Bold'},{value:'italic',label:'Italic'}]} />;Examples
Use single mode for a layout and multiple mode for formatting.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
options | | — | Choices; icon-only items still require a label. |
type? | | | Selection mode. |
value? | | — | Controlled choice or choices. |
defaultValue? | | — | Initial choice or choices. |
onValueChange? | | — | Reports the accepted state. |
allowEmpty? | | | Allow clearing a single choice. |
size? | | | Visual size; both retain 44pt targets. |
wrap? | | | Wrap rather than scroll. |
tooltip? | | | Show icon-only labels on hold. |
paintSelect? | | | Hold and paint choices. |
disabled? | | | Disable every choice. |
accessibilityLabel? | | — | Name of the group. |
haptics? | | | Selection feedback. |
motion? | | — | App motion override. |
className? | | — | Root classes. |
style? | | — | Root style. |
testID? | | — | Root identifier. |
Toggle group settings
| Prop | Does | Default |
|---|---|---|
| type | Single or multiple choices | single |
| allowEmpty | Clear a single choice | false |
| size | Small or medium surfaces with 44pt targets | md |
| wrap | Wrap instead of scroll | false |
| tooltip | Show icon labels on hold | true |
| paintSelect | Hold then paint choices | true |
| haptics | Selection feedback | true |
| motion | Shared app motion | App feel |
Composition and behavior
ButtonGroup performs actions; ToggleGroup represents state. Every icon-only item needs a label. Disabled reasons are exposed as accessibility hints. The single highlight glides; adjacent multiple choices join their inner corners.
Behavior and gestures
- Tap to choose or hold and paint across choices.
Accessibility
- Single choices use radios; multiple choices use selected toggle buttons.
Motion
- Uses the
select,toggleandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The dot fills with the toggle role; the cards variant moves a selection ring with the select role.
- Reduce Motion changes selection instantly.
Performance
- Plain row frames are retained for hit-testing; animation styles live in the highlight leaf.
Notes for AI
- Give options unique values; null means nothing selected.
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.