Skip to content

Radio Group Primitive

Types Primitives Slot Primitives

@radix-ui/react-radio-group


A group of selectable buttons, commonly referred to as radio buttons, wherein only one button can be checked simultaneously.

Installation

Install @radix-ui/react-radio-group

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

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

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

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

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

Usage

import * as React from 'react';
import * as RadioGroupPrimitive from '~/components/primitives/radio-group';
import { Text, View } from 'react-native';
function Example() {
const [value, setValue] = React.useState('Comfortable');
function onLabelPress(label: string) {
return () => {
setValue(label);
};
}
return (
<RadioGroupPrimitive.Root value={value} onValueChange={setValue}>
<View>
<RadioGroupPrimitive.Item value='Default' aria-labelledby='default-label'>
<RadioGroupPrimitive.Indicator />
</RadioGroupPrimitive.Item>
<Text nativeID='default-label' onPress={onLabelPress('Default')}>Default</Text>
</View>
<View>
<RadioGroupPrimitive.Item value='Comfortable' aria-labelledby='comfortable-label'>
<RadioGroupPrimitive.Indicator />
</RadioGroupPrimitive.Item>
<Text nativeID='comfortable-label' onPress={onLabelPress('Comfortable')}>Comfortable</Text>
</View>
<View>
<RadioGroupPrimitive.Item value='Compact' aria-labelledby='compact-label'>
<RadioGroupPrimitive.Indicator />
</RadioGroupPrimitive.Item>
<Text nativeID='compact-label' onPress={onLabelPress('Compact')}>Compact</Text>
</View>
</RadioGroupPrimitive.Root>
);
}

Props

Root

Extends View props

PropTypeNote
valuestring | undefined
onValueChange(val: string) => void
asChildboolean(optional)
disabledboolean(optional)

Item

Extends Pressable props

PropTypeNote
valuestring
aria-labelledbystringIts label’s nativeID
asChildboolean(optional)

Indicator

Extends View props

PropTypeNote
forceMountboolean(optional)
asChildboolean(optional)