Skip to content

Toggle Group Primitive

Slot Primitives

Types Primitives

Utils Primitives

@radix-ui/react-toggle-group


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

Installation

Install @radix-ui/react-toggle-group

Terminal window
npx expo install @radix-ui/react-toggle-group

Copy/paste the following code for web to ~/components/primitives/toggle-group/toggle-group.web.tsx

Copy/paste the following code for native to ~/components/primitives/toggle-group/toggle-group.tsx

Copy/paste the following code for types to ~/components/primitives/toggle-group/types.ts

Copy/paste the following code for exporting to ~/components/primitives/toggle-group/index.ts

Usage

import * as React from 'react';
import { Text, View } from 'react-native';
import * as ToggleGroupPrimitive from '~/components/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.