在几个互斥项里选一个,全部选项一眼可见。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 项(用选择框)
API
定位到「API」RadioGroup
定位到「RadioGroup」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
accessibilityLabel |
string |
— | |
direction |
'row' | 'column' |
— | |
class |
string |
— | |
testID |
string |
— | |
children |
JSX.Element |
— |
* 必填
RadioRow
定位到「RadioRow」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
checked * |
boolean |
— | |
onSelect * |
() => void |
— | |
label * |
string |
— | |
disabled |
boolean |
— | |
inline |
boolean |
— | 紧凑:不画行底与内边距(一行并排的「是 / 否」) |
testID |
string |
— | |
class |
string |
— | |
children |
JSX.Element |
— |
* 必填
RadioMark
定位到「RadioMark」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
checked * |
boolean |
— |
* 必填