Tabs
标签页组件
本页常规演示显式采用 Shadcn Rhea 外观,示例代码保持一致;这不修改公共组件的兼容默认值,也不代表全部浏览器、原生宿主和视觉验收已完成。Surface/Text 等中性原子仍保留各自公开语义,外观主题由消费组合提供。
这是 wc 的 tabs 组件
<wc-shadcn-tabs-root style-profile="rhea" default-value="account">
<wc-shadcn-tabs-list style-profile="rhea">
<wc-shadcn-tabs-trigger style-profile="rhea" value="account">Account</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="rhea" value="password">Password</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="rhea" value="billing" disabled>Billing</wc-shadcn-tabs-trigger>
</wc-shadcn-tabs-list>
<wc-shadcn-tabs-content style-profile="rhea" value="account">Make changes to your account here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="rhea" value="password">Change your password here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="rhea" value="billing">Billing tab is disabled in this preview.</wc-shadcn-tabs-content>
</wc-shadcn-tabs-root>Style Profile 预设展示
Section titled “Style Profile 预设展示”上游 Shadcn Registry 为 Tabs 定义了多个 style profile(vega、nova、maia、lyra、mira、luma、sera、rhea、new-york-v4)。当前仅 nova、rhea、new-york-v4 完成 bounded text-default 投影(见 internal/fixtures/shadcn-tabs-style/coverage.json),其余 profile 尚未支持,会在运行时拒绝。
以下三个示例使用完全相同的 children、defaultValue 和 disabled 状态,仅切换 styleProfile,以证明预设切换不会重置 value、focus 或 children。每个示例独立渲染,不共享运行时实例。
<wc-shadcn-tabs-root style-profile="nova" default-value="account">
<wc-shadcn-tabs-list style-profile="nova">
<wc-shadcn-tabs-trigger style-profile="nova" value="account">Account</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="nova" value="password">Password</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="nova" value="billing" disabled>Billing</wc-shadcn-tabs-trigger>
</wc-shadcn-tabs-list>
<wc-shadcn-tabs-content style-profile="nova" value="account">Make changes to your account here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="nova" value="password">Change your password here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="nova" value="billing">Billing tab is disabled in this preview.</wc-shadcn-tabs-content>
</wc-shadcn-tabs-root>Rhea(当前默认展示)
Section titled “Rhea(当前默认展示)”<wc-shadcn-tabs-root style-profile="rhea" default-value="account">
<wc-shadcn-tabs-list style-profile="rhea">
<wc-shadcn-tabs-trigger style-profile="rhea" value="account">Account</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="rhea" value="password">Password</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="rhea" value="billing" disabled>Billing</wc-shadcn-tabs-trigger>
</wc-shadcn-tabs-list>
<wc-shadcn-tabs-content style-profile="rhea" value="account">Make changes to your account here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="rhea" value="password">Change your password here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="rhea" value="billing">Billing tab is disabled in this preview.</wc-shadcn-tabs-content>
</wc-shadcn-tabs-root>New York v4
Section titled “New York v4”<wc-shadcn-tabs-root style-profile="new-york-v4" default-value="account">
<wc-shadcn-tabs-list style-profile="new-york-v4">
<wc-shadcn-tabs-trigger style-profile="new-york-v4" value="account">Account</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="new-york-v4" value="password">Password</wc-shadcn-tabs-trigger>
<wc-shadcn-tabs-trigger style-profile="new-york-v4" value="billing" disabled>Billing</wc-shadcn-tabs-trigger>
</wc-shadcn-tabs-list>
<wc-shadcn-tabs-content style-profile="new-york-v4" value="account">Make changes to your account here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="new-york-v4" value="password">Change your password here.</wc-shadcn-tabs-content>
<wc-shadcn-tabs-content style-profile="new-york-v4" value="billing">Billing tab is disabled in this preview.</wc-shadcn-tabs-content>
</wc-shadcn-tabs-root>Content mount 策略
Section titled “Content mount 策略”TabsContent 默认采用 lazy L1 view:
- 只有当前 panel 会物化 host view。
- panel 失活时会 detach view,但保留 Proto instance、状态与 exposes。
keepMounted={true}是唯一的 view retention 选项,会让 inactive panel 继续保留完整 view。
Web Component 会保留 custom element 作为 owner,并在 internal view detached 时隐藏该 owner;重新激活后,同一个 Proto instance 会在该 owner 内物化新的 view。
npx @proto.ui/cli@latest add wc shadcn-tabs
把 wc 换成 react、vue 或 vue2,即可生成对应宿主的 facade。
传入 value 进入受控模式。
| 属性 | 类型 | 默认值 |
|---|---|---|
defaultValue | string | '' |
orientation | 'horizontal' 'vertical' | horizontal |
activationMode | 'automatic' 'manual' | automatic |
这些属性属于 Root。List 的 orientation 默认 horizontal,loop 默认 false,a11yLabel 默认 ''。Trigger 的 value 默认 '',disabled 默认 false。Content 的 value 默认 '',keepMounted 默认 false。