跳转到内容
Nacre
组件配色
EN

单选 Radio

stableRadioGroup · RadioRow · RadioMark在画廊运行
RadioGroup
在浏览器里运行真实组件。

在几个互斥项里选一个,全部选项一眼可见。RadioRow 放在库的 RadioGroup 里;「是 / 否」用 inline 横排,项需要说明时用整行。

状态:stable · 组件: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="是否通知客户">
<RadioRow inline label="是" checked={notify() === 'yes'} onSelect={() => notify.set('yes')} />
<RadioRow inline label="否" checked={notify() === 'no'} onSelect={() => notify.set('no')} />
</RadioGroup>
)
}

不加 inline 时整行可点、悬停有底,适合竖排的一组设置;禁用项降到 40% 且键盘跳过。

手机:不加 inline 时整行可点,适合竖排的一组设置;禁用项降到 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="分配方式">
<RadioRow label="自动分配" checked={mode() === 'auto'} onSelect={() => mode.set('auto')} />
<RadioRow label="指定坐席" checked={mode() === 'agent'} onSelect={() => mode.set('agent')} />
<RadioRow label="转给主管(无权限)" checked={mode() === 'leader'} onSelect={() => mode.set('leader')} disabled />
</RadioGroup>
</View>
)
}

children 换掉默认文字,放标题 + 一行说明;label 仍是读屏名。

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="新会话接入">
<RadioRow label="立即接入" checked={reply() === 'now'} onSelect={() => reply.set('now')}>
<Text class={`${TOUCH ? TEXT_SIZE.body : TEXT_SIZE.small} text-foreground`}>立即接入</Text>
<Text class={`${TOUCH ? TEXT_SIZE.small : TEXT_SIZE.caption} text-muted-foreground`}>有空闲坐席时直接分配</Text>
</RadioRow>
<RadioRow label="进入排队" checked={reply() === 'queue'} onSelect={() => reply.set('queue')}>
<Text class={`${TOUCH ? TEXT_SIZE.body : TEXT_SIZE.small} text-foreground`}>进入排队</Text>
<Text class={`${TOUCH ? TEXT_SIZE.small : TEXT_SIZE.caption} text-muted-foreground`}>按优先级排队,超时转留言</Text>
</RadioRow>
</RadioGroup>
</View>
)
}

RadioMark 只画圆点,给自绘的选择卡片、表格行里用;交互和读屏由外层负责。

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>
)
}
键 行为
Tab 整组只停一次,落在已选项(没有就第一个可用项)
↑ ↓ / ← → 在组内移动并选中,跳过禁用项,首尾循环
Space 选中聚焦项
  • RadioGroup 的 accessibilityLabel 是组名(「分配方式」),读屏把组内各项读成一组 radio。
  • RadioRow 的 label 是读屏名,勾选态读作 checked。

该用

  • 放在 RadioGroup 里(方向键在组内走)
  • 「是 / 否」用横排
  • 默认选中最常用的一项

不该用

  • 只有一个选项(用勾选)
  • 直接引 nsh/base 的 RadioGroup
  • 超过 5 项(用选择框)
属性 类型 默认 说明
accessibilityLabel string —
direction 'row' | 'column' —
class string —
testID string —
children JSX.Element —

* 必填

属性 类型 默认 说明
checked * boolean —
onSelect * () => void —
label * string —
disabled boolean —
inline boolean — 紧凑:不画行底与内边距(一行并排的「是 / 否」)
testID string —
class string —
children JSX.Element —

* 必填

属性 类型 默认 说明
checked * boolean —

* 必填