suiss/uim · React Native Component

Collapsible

A section that shows or hides its content when a trigger is pressed.

Collapsible 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
Collapsible (open by default) on iOS in light mode

Collapsible is an unstyled root with a CollapsibleTrigger and a CollapsibleContent panel. It handles the open state and accessibility, and leaves the look to you.

Use it for a single show-more section. For a list of sections where opening one can close another, use Accordion.

Installation

$ pnpm dlx @esuiss/uim@latest add collapsible

Manual

  1. Add the pieces it builds on: the primitives components/primitives/collapsible.tsx.

  2. Copy the source into components/ui/collapsible.tsx:

uniwind/components/ui/collapsible.tsx
import * as CollapsiblePrimitive from "@/components/primitives/collapsible"

const Collapsible = CollapsiblePrimitive.Root

const CollapsibleTrigger = CollapsiblePrimitive.Trigger

const CollapsibleContent = CollapsiblePrimitive.Panel

export { Collapsible, CollapsibleContent, CollapsibleTrigger }
  1. Update the import paths to match your project.

Usage

<CollapsibleDemo initialOpen />

Put any content in CollapsibleTrigger, for example a Text and a caret Icon, and use render to render it as a Button. Use open with onOpenChange for controlled state, or defaultOpen for uncontrolled.

Set keepMounted on CollapsibleContent to keep the content mounted while closed.

Examples

Default

iOS
Collapsible on iOS in light mode

Disabled

A disabled collapsible whose trigger cannot toggle it.

iOS
Collapsible (disabled) on iOS in light mode

Accessibility

  • The trigger has the button role with expanded and disabled state.
  • Closed content is hidden from VoiceOver and TalkBack.