一组分层内容部分——称为选项卡面板——一次只能显示一个。
Make changes to your account here. Click save when you're done.
import * as React from "react";import { Tabs } from "radix-ui";import "./styles.css";const TabsDemo = () => (<Tabs.Root className="TabsRoot" defaultValue="tab1"><Tabs.List className="TabsList" aria-label="Manage your account"><Tabs.Trigger className="TabsTrigger" value="tab1">Account</Tabs.Trigger><Tabs.Trigger className="TabsTrigger" value="tab2">Password</Tabs.Trigger></Tabs.List><Tabs.Content className="TabsContent" value="tab1"><p className="Text">Make changes to your account here. Click save when you're done.</p><fieldset className="Fieldset"><label className="Label" htmlFor="name">Name</label><input className="Input" id="name" defaultValue="Pedro Duarte" /></fieldset><fieldset className="Fieldset"><label className="Label" htmlFor="username">Username</label><input className="Input" id="username" defaultValue="@peduarte" /></fieldset><div style={{ display: "flex", marginTop: 20, justifyContent: "flex-end" }} ><button className="Button green">Save changes</button></div></Tabs.Content><Tabs.Content className="TabsContent" value="tab2"><p className="Text">Change your password here. After saving, you'll be logged out.</p><fieldset className="Fieldset"><label className="Label" htmlFor="currentPassword">Current password</label><input className="Input" id="currentPassword" type="password" /></fieldset><fieldset className="Fieldset"><label className="Label" htmlFor="newPassword">New password</label><input className="Input" id="newPassword" type="password" /></fieldset><fieldset className="Fieldset"><label className="Label" htmlFor="confirmPassword">Confirm password</label><input className="Input" id="confirmPassword" type="password" /></fieldset><div style={{ display: "flex", marginTop: 20, justifyContent: "flex-end" }} ><button className="Button green">Change password</button></div></Tabs.Content></Tabs.Root>);export default TabsDemo;
可以是可控或不可控的。
支持水平/垂直方向。
支持自动/手动激活。
完全的键盘导航。
从命令行安装组件。
导入所有部分并将它们组合在一起。
包含所有选项卡组件部分。
包含沿活动内容边缘对齐的触发器。
激活其关联内容的按钮。
包含与每个触发器关联的内容。
您可以通过使用 orientation
属性来创建垂直选项卡。