Radio

The Radio component presents users with predefined choices and enables them to select only one option. It is commonly used for providing a single-choice selection in forms or surveys.
Installation
API Reference
This is an illustration of Radio component.
size
isInvalid
isDisabled
<RadioGroup>
<Radio value="change" size="md" isInvalid={false} isDisabled={false}>
<RadioIndicator mr="$2">
<RadioIcon as={CircleIcon} strokeWidth={1} />
</RadioIndicator>
<RadioLabel>Label</RadioLabel>
</Radio>
</RadioGroup>

Installation

Step 1: Install the following dependencies:

npm i @gluestack-ui/radio lucide-react-native

Step 2: Copy and paste the following code into your project.

"use client"
import { createRadio } from "@gluestack-ui/radio"
import { Pressable, View, Platform, Text } from "react-native"
import { styled, AsForwarder } from "@gluestack-style/react"
const StyledRoot = styled(
// @ts-ignore
Platform.OS === "web" ? View : Pressable,
{
flexDirection: "row",
justifyContent: "flex-start",
alignItems: "center",
variants: {
size: {
lg: {
_text: {
props: {
size: "lg",
},
},
_icon: {
props: {
size: "md",
},
},
_indicator: {
p: 2,
h: "$6",
w: "$6",
},
},
md: {
_text: {
props: {
size: "md",
},
},
_icon: {
props: {
size: "sm",
},
},
_indicator: {
p: 1.5,
h: "$5",
w: "$5",
},
},
sm: {
_text: {
props: {
size: "sm",
},
},
_icon: {
props: {
size: "2xs",
},
},
_indicator: {
p: 1,
h: "$4",
w: "$4",
},
},
},
},
defaultProps: {
size: "md",
},
_web: {
cursor: "pointer",
":disabled": {
cursor: "not-allowed",
},
},
},
{
descendantStyle: ["_icon", "_text", "_indicator"],
ancestorStyle: ["_radio"],
}
)
const StyledGroup = styled(View, {}, { descendantStyle: ["_radio"] })
const StyledIcon = styled(
AsForwarder,
{
color: "$background800",
// defaultProps: {
// size: 'md',
// },
variants: {
size: {
"2xs": {
h: "$3",
w: "$3",
props: {
// @ts-ignore
size: 12,
},
},
xs: {
h: "$3.5",
w: "$3.5",
props: {
//@ts-ignore
size: 14,
},
},
sm: {
h: "$4",
w: "$4",
props: {
//@ts-ignore
size: 16,
},
},
md: {
h: "$4.5",
w: "$4.5",
props: {
//@ts-ignore
size: 18,
},
},
lg: {
h: "$5",
w: "$5",
props: {
//@ts-ignore
size: 20,
},
},
xl: {
h: "$6",
w: "$6",
props: {
//@ts-ignore
size: 24,
},
},
},
},
borderRadius: "$full",
":checked": {
color: "$primary600",
":hover": {
color: "$primary700",
":disabled": {
color: "$primary600",
},
},
},
},
{
ancestorStyle: ["_icon"],
resolveProps: ["color"],
},
{
propertyTokenMap: {
stroke: "colors",
fill: "colors",
},
}
)
const StyledIndicator = styled(
View,
{
justifyContent: "center",
alignItems: "center",
bg: "transparent",
borderColor: "$border400",
borderWidth: 2,
borderRadius: 999,
_web: {
":focusVisible": {
outlineWidth: 2,
outlineColor: "$primary700",
outlineStyle: "solid",
},
},
":checked": {
borderColor: "$primary600",
bg: "transparent",
},
":hover": {
borderColor: "$border500",
bg: "transparent",
":checked": {
bg: "transparent",
borderColor: "$primary700",
},
":invalid": {
borderColor: "$error700",
},
":disabled": {
":invalid": {
borderColor: "$error400",
opacity: 0.4,
},
borderColor: "$border400",
opacity: 0.4,
},
},
":active": {
bg: "transparent",
borderColor: "$primary800",
},
":invalid": {
borderColor: "$error700",
},
":disabled": {
opacity: 0.4,
":checked": {
borderColor: "$border400",
bg: "transparent",
},
":invalid": {
borderColor: "$error400",
},
},
},
{ ancestorStyle: ["_indicator"] }
)
const StyledText = styled(
Text,
{
color: "$text700",
flex: 1,
fontWeight: "$normal",
fontFamily: "$body",
fontStyle: "normal",
letterSpacing: "$md",
variants: {
isTruncated: {
true: {
props: {
// @ts-ignore
numberOfLines: 1,
ellipsizeMode: "tail",
},
},
},
bold: {
true: {
fontWeight: "$bold",
},
},
underline: {
true: {
textDecorationLine: "underline",
},
},
strikeThrough: {
true: {
textDecorationLine: "line-through",
},
},
size: {
"2xs": {
fontSize: "$2xs",
},
xs: {
fontSize: "$xs",
},
sm: {
fontSize: "$sm",
},
md: {
fontSize: "$md",
},
lg: {
fontSize: "$lg",
},
xl: {
fontSize: "$xl",
},
"2xl": {
fontSize: "$2xl",
},
"3xl": {
fontSize: "$3xl",
},
"4xl": {
fontSize: "$4xl",
},
"5xl": {
fontSize: "$5xl",
},
"6xl": {
fontSize: "$6xl",
},
},
sub: {
true: {
fontSize: "$xs",
},
},
italic: {
true: {
fontStyle: "italic",
},
},
highlight: {
true: {
bg: "$yellow500",
},
},
},
defaultProps: {
size: "md",
},
},
{
ancestorStyle: ["_text"],
}
)
const StyledLabel = styled(
StyledText,
{
color: "$text600",
":checked": {
color: "$text900",
},
":hover": {
color: "$text900",
":checked": {
color: "$text900",
},
":disabled": {
color: "$text600",
":checked": {
color: "$text900",
},
},
},
":active": {
color: "$text900",
":checked": {
color: "$text900",
},
},
":disabled": {
opacity: 0.4,
},
_web: {
MozUserSelect: "none",
WebkitUserSelect: "none",
msUserSelect: "none",
userSelect: "none",
},
},
{ ancestorStyle: ["_text"] }
)
export const Radio = createRadio({
Root: StyledRoot,
Group: StyledGroup,
Icon: StyledIcon,
Indicator: StyledIndicator,
Label: StyledLabel,
})
export const RadioGroup = Radio.Group
export const RadioIcon = Radio.Icon
export const RadioIndicator = Radio.Indicator
export const RadioLabel = Radio.Label

Step 3: Update the import paths to match your project setup.

API Reference

To use this component in your project, include the following import statement in your file.
import { Radio } from "@gluestack-ui/themed"
export default () => (
<RadioGroup>
<Radio>
<RadioIndicator>
<RadioIcon />
</RadioIndicator>
<RadioLabel />
</Radio>
</RadioGroup>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

Radio

Contains all Radio related layout style props and actions. It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
value
string
-
The value to be used in the radio input. This is the value that will be returned on form submission.
onChange
function
-
Function called when the state of the radio changes.
isDisabled
bool
false
To manually set disable to the radio.
isInvalid
bool
false
To manually set invalid to the radio.
isHovered
bool
false
To manually set hover to the radio.
isFocusVisible
bool
false
To manually set focus visible state to the radio.
isIndeterminate
bool
false
To manually set indeterminate to the radio.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_text
Prop to style RadioLabel Component
_icon
Prop to style RadioIcon Component
_indicator
Prop to style RadioIndicator Component

RadioIndicator

Contains all Indicator related layout style props and actions. It inherits all the properties of React Native's View component.

RadioIcon

Contains all Icon related layout style props and actions. It inherits all the properties of gluestack Style's AsForwarder component.

RadioLabel

Contains all Label related layout style props and actions. It inherits all the properties of React Native's Text component.

RadioGroup

Contains all Group related layout style props and actions. It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
value
string
-
The value of the radio group.
onChange
function
-
The callback fired when any children Radio is checked or unchecked.
isReadOnly
bool
false
To manually set read-only to the radio group.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_radio
Prop to style Radio Component

Features

  • Keyboard support for actions.
  • Support for hover, focus and active states.

Accessibility

We have outlined the various features that ensure the Radio component is accessible to all users, including those with disabilities. These features help ensure that your application is inclusive and meets accessibility standards. Adheres to the WAI-ARIA design pattern.

Keyboard

  • Tab: Moves focus to the next focusable element.
  • Shift + Tab: Moves focus to the previous focusable element.
  • Space: To check or uncheck focused radio.

Screen Reader

  • VoiceOver: When the radio is focused, the screen reader will announce it's a radio and it's current state (check or uncheck) and it's label.

Focus Management

  • The onFocus and onBlur props manage focus states and provide visual cues to users. This is especially important for users who rely on keyboard navigation.

States

  • In error state, aria-invalid will be passed to indicate that the radio input has an error, and providing support for an aria-errormessage to describe the error in more detail.
  • In disabled state, aria-hidden will be passed to make radio input not focusable.
  • In required state, aria-required will be passed to indicate that the radio input is required.

Props

Radio component is created using Pressable component from react-native. It extends all the props supported by React Native Pressable, utility props and the props mentioned below.

Radio

Name
Value
Default
size
lg | md | sm
md

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

Multiple Radio

Radio buttons provide a mutually exclusive selection mechanism, allowing users to choose a single option from a set of related choices.
function App() {
const [values, setValues] = React.useState("Eng")
return (
<RadioGroup value={values} onChange={setValues}>
<VStack space="sm">
<Radio value="Eng">
<RadioIndicator mr="$2">
<RadioIcon as={CircleIcon} />
</RadioIndicator>
<RadioLabel>English</RadioLabel>
</Radio>
<Radio value="Fre">
<RadioIndicator mr="$2">
<RadioIcon as={CircleIcon} />
</RadioIndicator>
<RadioLabel>French</RadioLabel>
</Radio>
<Radio value="Ger">
<RadioIndicator mr="$2">