可收起的内容:Disclosure 是带三角的分组标题(可带前置图标、条数、行尾附加、按钮外的独立操作,箭头放行首或行尾),DisclosureRow 是整行可点、点开看详情的记录行。两者只管标题这一行,内容的开合由调用方按 expanded 用 If 或 Collapsible 接。
状态:stable · 组件:Disclosure、DisclosureRow
引入
定位到「引入」import { Disclosure, DisclosureRow } from 'nacre'用法
定位到「用法」受控 expanded + onPress;展开的内容写 pl-[18px],与标题文字对齐。
import { Text, View, signal } from 'nsh'import { Disclosure, TEXT_SIZE } from 'nacre'
export function DisclosureUsage() { const open = signal(true) return ( <View class="w-[320px] max-w-full gap-2"> <Disclosure title="质检结果" expanded={open()} onPress={() => open.update((v) => !v)} /> <If when={open()}> <Text class={`pl-[18px] ${TEXT_SIZE.small} text-muted-foreground`}>服务态度 5 分 · 问题已解决 · 无违规用语</Text> </If> </View> )}示例
定位到「示例」多个分组
定位到「多个分组」每组各自开合;默认展开最常用的一组,标题里带条数;禁用组不可点。
import { Text, View, signal } from 'nsh'import { Disclosure, TEXT_SIZE } from 'nacre'
export function DisclosureGroups() { const result = signal(true) const hits = signal(false) return ( <View class="w-[320px] max-w-full gap-2"> <Disclosure title="整体结果" expanded={result()} onPress={() => result.update((v) => !v)} /> <If when={result()}> <Text class={`pl-[18px] ${TEXT_SIZE.small} text-muted-foreground`}>本次会话满意度 4.8,首次响应 12 秒</Text> </If> <Disclosure title="实时命中(3)" expanded={hits()} onPress={() => hits.update((v) => !v)} /> <If when={hits()}> <View class="pl-[18px] gap-1"> {['开户', '出金', '投诉'].map((word) => <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>{`$命中关键词:${word}`}</Text>)} </View> </If> <Disclosure title="禁用的分组" expanded={false} disabled onPress={() => {}} /> </View> )}次要说明行
定位到「次要说明行」variant=“subtle” + chevron=“end”:前置图标、常规字重的次要色标题、行尾箭头,放在正文旁边(推理、工具、引用)。工具的状态图标放 trailing,在箭头左边。同一处的几块用同一种外观。
import { Text, View, signal } from 'nsh'import { Disclosure, Icon, TEXT_SIZE } from 'nacre'
export function DisclosureSubtle() { const reasoning = signal(false) const tool = signal(false) const sources = signal(false) return ( <View class="w-[320px] max-w-full gap-1"> <Disclosure testID="subtle-reasoning" variant="subtle" chevron="end" leading={<Icon name="sparkles" size={13} color="muted-foreground" />} title="思考 4 秒" expanded={reasoning()} onPress={() => reasoning.update((v) => !v)} /> <If when={reasoning()}> <Text class={`pl-3 ml-1.5 border-l border-border ${TEXT_SIZE.small} text-muted-foreground`}>先查客户的开户进度,再看资料是否齐全。</Text> </If> <Disclosure testID="subtle-tool" variant="subtle" chevron="end" leading={<Icon name="wrench" size={13} color="muted-foreground" />} title="query_account_status" trailing={<Icon name="check" size={13} color="muted-foreground" />} expanded={tool()} onPress={() => tool.update((v) => !v)} /> <Disclosure testID="subtle-sources" variant="subtle" chevron="end" leading={<Icon name="file" size={13} color="muted-foreground" />} title="引用 3 条资料" expanded={sources()} onPress={() => sources.update((v) => !v)} /> </View> )}面板分区头
定位到「面板分区头」variant=“section” + chevron=“end”:图标、标题、紧跟标题的条数(suffix)、行尾的元信息(trailing,窄时先截断),箭头带悬停底。
手机:variant=“section” + chevron=“end”:图标、标题、条数(suffix)、行尾元信息(trailing,窄时先截断),整行点按展开。
import { Text, View, signal } from 'nsh'import { Disclosure, Icon, TEXT_SIZE } from 'nacre'
export function DisclosureSection() { const open = signal(true) return ( <View class="w-[320px] max-w-full gap-2"> <Disclosure testID="section-remark" variant="section" chevron="end" leading={<Icon name="sparkles" size={13} color="muted-foreground" />} title="服务小记" suffix={<Text class={`${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>3 条</Text>} trailing={<Text class={`shrink min-w-0 truncate ${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>林嘉怡 · 11-24 14:05</Text>} expanded={open()} onPress={() => open.update((v) => !v)} /> <If when={open()}> <Text class={`${TEXT_SIZE.small} text-muted-foreground`}>客户已补交地址证明,待审核后回电。</Text> </If> </View> )}分组头与独立操作
定位到「分组头与独立操作」variant=“group”:列表的分组头,条数放 suffix;「清空」这类操作放 actions,渲染在展开按钮之外,点它不切换展开。
import { Text, View, signal } from 'nsh'import { Button, Disclosure, TEXT_SIZE } from 'nacre'
export function DisclosureActions() { const active = signal(true) const ended = signal(true) const endedCount = signal(12) return ( <View class="w-[320px] max-w-full"> <Disclosure testID="group-active" variant="group" class="h-7 px-1.5 rounded-md" title="进行中" suffix={<Text class={`${TEXT_SIZE.small} text-muted-foreground tabular-nums`}>5</Text>} expanded={active()} onPress={() => active.update((v) => !v)} /> <Disclosure testID="group-ended" variant="group" class="h-7 px-1.5 rounded-md" title="已结束" suffix={<Text testID="group-ended-count" class={`${TEXT_SIZE.small} text-muted-foreground tabular-nums`}>{String(endedCount())}</Text>} actions={ <If when={endedCount() > 0}> <Button testID="group-ended-clear" variant="subtle" size="xs" onPress={() => endedCount.set(0)}> 清空 </Button> </If> } expanded={ended()} onPress={() => ended.update((v) => !v)} /> </View> )}记录行
定位到「记录行」DisclosureRow 放在卡片里当通话记录的头:时间、标签、状态、摘要由调用方排,chevron 自己放;一次只展开一条。
import { Text, View, signal } from 'nsh'import { DisclosureRow, Icon, Tag, TEXT_SIZE } from 'nacre'
const calls = () => [ { id: 'c1', time: '今天 14:05', direction: '呼入', status: '已接通', summary: '3 分 12 秒 · 林嘉怡 · 开户 / 资料补充' }, { id: 'c2', time: '昨天 09:40', direction: '呼出', status: '未接通', summary: '回访 · 陈智源 · 出金未到账' },]
export function DisclosureRows() { const open = signal<string | null>(null) return ( <View class="w-[320px] max-w-full gap-1.5"> {calls().map((call) => ( <View class="rounded-lg bg-card border border-border"> <DisclosureRow testID={`call-row-${call.id}`} accessibilityLabel={`${call.time} · ${call.direction} · ${call.status}`} expanded={open() === call.id} onPress={() => open.set(open() === call.id ? null : call.id)} > <View class="flex-row items-center gap-1.5"> <Text class={`shrink-0 ${TEXT_SIZE.caption} text-muted-foreground tabular-nums`}>{call.time}</Text> <Tag label={call.direction} /> <View class="flex-1" /> <Text class={`shrink min-w-0 truncate ${TEXT_SIZE.caption} text-muted-foreground`}>{call.status}</Text> <Icon name={open() === call.id ? 'chevron-down' : 'chevron-right'} size={10} color="muted-foreground" /> </View> <Text class={`truncate ${TEXT_SIZE.caption} text-muted-foreground`}>{call.summary}</Text> </DisclosureRow> <If when={open() === call.id}> <View class="px-2.5 pb-2.5"> <Text class={`${TEXT_SIZE.small} text-text-secondary`}>小记:客户已补交地址证明,待审核后回电。</Text> </View> </If> </View> ))} </View> )}长标题
定位到「长标题」标题单行截断,悬停看全文;放在窄栏里也不折行、不撑高。
手机:标题单行截断,展开后看全文;窄屏也不折行、不撑高。
import { Text, View, signal } from 'nsh'import { Disclosure, TEXT_SIZE } from 'nacre'
export function DisclosureLongTitle() { const open = signal(false) return ( <View class="w-[200px] max-w-full gap-2"> <Disclosure title="港股开户 · 未解决 · 近 30 天 · 二线支持" expanded={open()} onPress={() => open.update((v) => !v)} /> <If when={open()}> <Text class={`pl-[18px] ${TEXT_SIZE.small} text-muted-foreground`}>共 12 条会话</Text> </If> </View> )}键盘
定位到「键盘」| 键 | 行为 |
|---|---|
| Tab | 聚焦标题或记录行;有 actions 时下一个 Tab 停在操作上 |
| Space / Return | 切换展开收起 |
无障碍
定位到「无障碍」- role 是 button,展开态读作 expanded / collapsed。
- Disclosure 的读屏名默认是标题;DisclosureRow 不给 accessibilityLabel 时读行内文字,行里内容多时给一个简短的读屏名。
- 禁用项不进 Tab 序列,40% 透明。
- leading、suffix、trailing 在展开按钮里,读屏只念读屏名;里面有要单独读的状态(工具失败),把它写进 accessibilityLabel。
- actions 在按钮之外,各自是独立的 Tab 停靠点与读屏元素;不要把可点的控件放进 leading / suffix / trailing。
该用 / 不该用
定位到「该用 / 不该用」该用
- 默认展开最常用的一组
- 展开内容缩进 18 与标题文字对齐
- 记录行一次只展开一条
- 同一处的几块折叠标题用同一个 variant 和箭头位置
- 分组标题上的操作(清空、新建)放 actions
不该用
- 把唯一的内容收起来
- 用 Disclosure 做导航(用侧栏或 Tab)
- 在 DisclosureRow 里放按钮(展开后的详情里放)
- 把按钮、分段控件塞进 suffix / trailing(会嵌在展开按钮里)
API
定位到「API」Disclosure
定位到「Disclosure」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
title * |
string |
— | 分组标题,单行截断、悬停看全文 |
expanded * |
boolean |
— | |
onPress * |
() => void |
— | |
disabled |
boolean |
— | |
variant |
DisclosureVariant |
'default' |
外观,默认 default |
chevron |
'start' | 'end' |
— | 箭头在行首(访达的展开三角,默认)还是行尾(附加说明行、面板分区头) |
leading |
JSX.Element |
— | 标题前的图标或任意节点(图标 13 / 14,muted-foreground) |
suffix |
JSX.Element |
— | 紧跟标题的小字:条数、徽标 |
trailing |
JSX.Element |
— | 行尾右对齐的附加:状态图标、元信息文字;窄时先收缩它,在行尾箭头左边 |
actions |
JSX.Element |
— | 与标题同一行、在展开按钮之外的独立操作(清空、新建):点它不切换展开 |
accessibilityLabel |
string |
— | 读屏名;不给时读标题 |
tooltip |
string |
— | 悬停展开按钮时的提示(如「收起」/「展开」);标题文字截断时仍悬停看全文 |
testID |
string |
— | |
class |
string |
— | 根节点的布局类(高度、内边距、外边距、整行悬停底) |
* 必填
DisclosureRow
定位到「DisclosureRow」| 属性 | 类型 | 默认 | 说明 |
|---|---|---|---|
expanded * |
boolean |
— | |
onPress * |
() => void |
— | |
disabled |
boolean |
— | |
accessibilityLabel |
string |
— | 读屏名;不给时读屏念行内文字 |
testID |
string |
— | |
class |
string |
— | 根节点的布局类 |
children |
JSX.Element |
— | 行的内容(时间、标签、状态、摘要),由调用方排;展开后的详情放在行外 |
* 必填