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.
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
Copy/paste the following code for native to ~/components/primitives/toggle-group/index.tsx
Copy/paste the following code for types to ~/components/primitives/toggle-group/types.ts
Usage
Props
Root
Extends View
props
Prop | Type | Note |
---|---|---|
type | ’single’ | ‘multiple’ | |
value | string | undefined | string[] | |
onValueChange | (val: string | undefined | string[]) => void | |
asChild | boolean | (optional) |
disabled | boolean | (optional) |
rovingFocus | boolean | Web only (optional) |
orientation | ’horizontal’ | ‘vertical’ | Web only (optional) |
dir | ’ltr’ | ‘rtl’ | Web only (optional) |
ltr | boolean | Web only (optional) |
Item
Extends Pressable
props
Prop | Type | Note |
---|---|---|
asChild | boolean | (optional) |
value | string |
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
.