Skip to content
Nacre
Color palette
中文

Radio

stableRadioGroup · RadioRow · RadioMarkOpen in playground
RadioGroup
Runs the real component in your browser.

Picks one of a few mutually exclusive options, all visible at a glance. RadioRow goes in the library’s RadioGroup; use inline rows for “Yes / No”, and full rows when options need a description.

Status: stable · Components: RadioGroup, RadioRow, RadioMark

import { RadioGroup, RadioRow, RadioMark } from 'nacre'
import { signal } from 'nsh'
import { RadioGroup, RadioRow } from 'nacre'
export function RadioUsage() {
const notify = signal<'yes' | 'no'>('yes')
return (
<RadioGroup direction="row" accessibilityLabel="Notify the customer">
<RadioRow inline label="Yes" checked={notify() === 'yes'} onSelect={() => notify.set('yes')} />
<RadioRow inline label="No" checked={notify() === 'no'} onSelect={() => notify.set('no')} />
</RadioGroup>
)
}

Without inline, the whole row is pressable and gets a fill on hover, which suits a vertical group of settings; disabled options drop to 40% and the keyboard skips them.

Phone: Without inline the whole row is tappable, for a vertical group of settings; disabled options drop to 40%.

import { View, signal } from 'nsh'
import { RadioGroup, RadioRow, TOUCH } from 'nacre'
export function RadioRows() {
const mode = signal<'auto' | 'agent' | 'leader'>('agent')
return (
<View class={`${TOUCH ? 'w-full' : 'w-[260px] max-w-full rounded-lg border border-border p-1'}`}>
<RadioGroup accessibilityLabel="Assignment method">
<RadioRow label="Auto-assign" checked={mode() === 'auto'} onSelect={() => mode.set('auto')} />
<RadioRow label="Specific agent" checked={mode() === 'agent'} onSelect={() => mode.set('agent')} />
<RadioRow label="Transfer to supervisor (no permission)" checked={mode() === 'leader'} onSelect={() => mode.set('leader')} disabled />
</RadioGroup>
</View>
)
}

children replace the default text with a title plus a one-line description; label is still the screen reader name.

import { Text, View, signal } from 'nsh'
import { RadioGroup, RadioRow, TEXT_SIZE, TOUCH } from 'nacre'
export function RadioWithDescription() {
const reply = signal<'now' | 'queue'>('now')
return (
<View class={`${TOUCH ? 'w-full' : 'w-[300px] max-w-full'}`}>
<RadioGroup accessibilityLabel="New chat intake">
<RadioRow label="Accept now" checked={reply() === 'now'} onSelect={() => reply.set('now')}>
<Text class={`${TOUCH ? TEXT_SIZE.body : TEXT_SIZE.small} text-foreground`}>Accept now</Text>
<Text class={`${TOUCH ? TEXT_SIZE.small : TEXT_SIZE.caption} text-muted-foreground`}>Assign directly when an agent is free</Text>
</RadioRow>
<RadioRow label="Queue" checked={reply() === 'queue'} onSelect={() => reply.set('queue')}>
<Text class={`${TOUCH ? TEXT_SIZE.body : TEXT_SIZE.small} text-foreground`}>Queue</Text>
<Text class={`${TOUCH ? TEXT_SIZE.small : TEXT_SIZE.caption} text-muted-foreground`}>Queue by priority; turn into a message on timeout</Text>
</RadioRow>
</RadioGroup>
</View>
)
}

RadioMark draws only the dot, for custom selection cards and table rows; the outer element handles interaction and screen readers.

import { View } from 'nsh'
import { RadioMark } from 'nacre'
export function RadioMarkOnly() {
return (
<View class="flex-row items-center gap-3">
<RadioMark checked />
<RadioMark checked={false} />
</View>
)
}
Key Action
Tab Stops once for the whole group, on the selected option (or the first enabled one if none)
↑ ↓ / ← → Move within the group and select, skipping disabled options and wrapping around
Space Select the focused option
  • RadioGroup’s accessibilityLabel is the group name (“Assignment method”); screen readers read its options as one radio group.
  • RadioRow’s label is the screen reader name, and the selected state reads as checked.

Do

  • Put rows in a RadioGroup (arrow keys move within it)
  • Lay out “Yes / No” horizontally
  • Select the most common option by default

Don’t

  • Offer a single option (use a checkbox)
  • Import RadioGroup from nsh/base directly
  • Use more than 5 options (use a select)

Property descriptions follow the Chinese source comments.

Prop Type Default Description
accessibilityLabel string —
direction 'row' | 'column' —
class string —
testID string —
children JSX.Element —

* required

Prop Type Default Description
checked * boolean —
onSelect * () => void —
label * string —
disabled boolean —
inline boolean — 紧凑:不画行底与内边距(一行并排的「是 / 否」)
testID string —
class string —
children JSX.Element —

* required

Prop Type Default Description
checked * boolean —

* required