ZUI

Search documentation

Find a page or a heading.

Toggle

A two-state button, announced as a button with its selected state, drawn on the muted background while pressed.

Installation

bash

The CLI writes components/ui/toggle.tsx, installs Text, Icon and Utils, and adds @rn-primitives/toggle and class-variance-authority.

Usage

tsx
tsx

A Text child is the label and takes the toggle's label classes. An Icon child takes a 16px size. A toggle with only an icon has no text for a screen reader, so name it with aria-label.

API reference

Toggle

Takes every prop of the @rn-primitives/toggle root, plus:

Toggle is controlled. Pressing it calls onPressedChange with the new value, and it draws as pressed once pressed follows. It is announced as a button, or as the role given, with its selected and disabled state. A disabled toggle is dimmed and ignores presses. aria-invalid draws the destructive border. React Native does not announce it, so carry the error in accessibilityHint or in a Text the user can reach.

toggleVariants

The view classes of each variant and size, for a pressable that is not a Toggle but should look like one.