suiss/uim · React Native Component

Toggle Group

A set of toggles that share one value, for formatting controls, alignment options and segmented controls.

Toggle Group is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Toggle Group on iOS in light mode

ToggleGroup is built on the toggle group primitive and lays out ToggleGroupItem toggles in a row or a column. Items take the same variant and size styles as Toggle. The spacing prop sets the gap between items in steps of 4 points.

With spacing={0}, the group changes shape: the default variant becomes a segmented control on a bg-control track, and the outline variant joins items into one bordered strip. In a single-selection segmented control, the selected item is marked by a raised indicator that slides to the new item when the selection changes, like Tabs. In a multiple segmented control, each pressed item is raised on its own. Use the segmented style for switching views and the spaced style for toolbars.

Installation

$ pnpm dlx @esuiss/uim@latest add toggle-group

The CLI also adds what it builds on: Icon, Text, Toggle.

Manual

  1. Install the dependencies:
npx expo install class-variance-authority cn react-native-reanimated react-native-worklets
  1. Add the pieces it builds on: Icon, Text, Toggle, and the primitives components/primitives/toggle.tsx, components/primitives/toggle-group.tsx, components/primitives/types.tsx, components/primitives/use-render.tsx.

  2. Copy the source into components/ui/toggle-group.tsx:

uniwind/components/ui/toggle-group.tsx
import type { VariantProps } from "class-variance-authority"
import { cn } from "cn"
import * as React from "react"
import { Pressable } from "react-native"
import Animated, {
  Easing,
  LinearTransition,
  ReduceMotion,
} from "react-native-reanimated"
import {
  Toggle as TogglePrimitive,
  type ToggleState,
} from "@/components/primitives/toggle"
import {
  ToggleGroupIndicator as ToggleGroupIndicatorPrimitive,
  ToggleGroup as ToggleGroupPrimitive,
  1. Update the import paths to match your project.

Usage

import { ToggleGroup, ToggleGroupItem, ToggleGroupIcon } from "@/components/ui/toggle-group"
<FormattingDemo />

The value is always an array of strings. Use value and onValueChange for controlled use, or defaultValue. Set multiple to allow more than one pressed item; without it, pressing an item replaces the selection.

Give each ToggleGroupItem a value. Put icons in a ToggleGroupIcon, which sizes them to 16 points, and give icon-only items an accessibilityLabel. orientation switches between a row and a column, and disabled on the group turns off every item.

Examples

Outline

The outline variant.

iOS
Toggle Group (outline) on iOS in light mode

Attached

Outlined items joined into one strip with spacing={0}.

iOS
Toggle Group (attached) on iOS in light mode

Sizes

The sm, default and lg sizes.

iOS
Toggle Group (sizes) on iOS in light mode

Segmented

A single-selection segmented control for calendar views.

iOS
Toggle Group (segmented) on iOS in light mode

Segmented vertical

The segmented control in a vertical orientation.

iOS
Toggle Group (segmented vertical) on iOS in light mode

Segmented multiple

A segmented control that allows several selected items.

iOS
Toggle Group (segmented multiple) on iOS in light mode

Segmented sizes

Segmented controls at each size.

iOS
Toggle Group (segmented sizes) on iOS in light mode

Single selection

Outlined alignment options where only one item can be pressed.

iOS
Toggle Group (single selection) on iOS in light mode

Vertical

Joined outline items stacked in a column.

iOS
Toggle Group (vertical) on iOS in light mode

Disabled

A disabled group.

iOS
Toggle Group (disabled) on iOS in light mode

API Reference

ToggleGroup

Container that holds the shared value.

ExtendsReact.ComponentProps<typeof ToggleGroupPrimitive>
PropType
About
Gap between items in steps of 4 points. 0 joins the items. Defaults to 2.
Type
number
Default
2

ToggleGroupItem

One toggle in the group.

ExtendsReact.ComponentProps<typeof TogglePrimitive>

ToggleGroupIcon

Icon sized for a toggle group item.

ExtendsReact.ComponentProps<typeof Icon>

Accessibility

  • A single-selection group has the radiogroup role and its items have the radio role.
  • A multiple group has the group role and its items have the togglebutton role.
  • Items report checked and disabled states to VoiceOver and TalkBack.
  • The sliding segmented indicator is hidden from VoiceOver and TalkBack.
  • Icon-only items need an accessibilityLabel; label the group itself with accessibilityLabel when its purpose is not clear from context.

Notes

  • Pressed items use bg-item-selected and text-link; the segmented indicator and pressed segmented items use bg-surface-raised with a small shadow in light mode and bg-label-quaternary in dark mode.
  • The indicator slides over 300 ms and respects the system reduce motion setting. It is hidden when the selected item is disabled.
  • Colors follow the system appearance.