Skip to content

Toggle Group Primitive

A collection of buttons with true or false states, which can be activated or deactivated by toggling.

Installation

Install the component via your command line.

Terminal window
npx expo install @rn-primitives/toggle-group

Usage

import * as React from 'react';
import { Text, View } from 'react-native';
import * as ToggleGroupPrimitive from '@rn-primitives/toggle-group';
function Example() {
const [multipleValue, setMultipleValue] = React.useState<string[]>([]);
return (
<ToggleGroupPrimitive.Root type='multiple' value={multipleValue} onValueChange={setMultipleValue}>
<ToggleGroupPrimitive.ToggleItem value='bold'>
<Text>Bold</Text>
</ToggleGroupPrimitive.ToggleItem>
<ToggleGroupPrimitive.ToggleItem value='italic'>
<Text>Italic</Text>
</ToggleGroupPrimitive.ToggleItem>
</ToggleGroupPrimitive.Root>
);
}

Props

Root

Extends View props

PropTypeNote
type’single’ | ‘multiple’
valuestring | undefined | string[]
onValueChange(val: string | undefined | string[]) => void
asChildboolean(optional)
disabledboolean(optional)
rovingFocusbooleanWeb only (optional)
orientation’horizontal’ | ‘vertical’Web only (optional)
dir’ltr’ | ‘rtl’Web only (optional)
ltrbooleanWeb only (optional)

Item

Extends Pressable props

PropTypeNote
asChildboolean(optional)
valuestring

useRootContext

Must be used within a Root component. It provides the following values from the dropdown menu: value, onValueChange, type, and disabled.

useItemContext

Must be used within a Item component. It provides the following values from the dropdown menu: value.