侧边栏
用途
Sidebar uses a native <aside> next to your page content. A3S UI owns the fixed positioning, overlay behavior, active states, nested lists, and details submenu styling. Your app still owns the navigation data and current route.
Add your sidebar HTML
RTL
在侧边栏或父元素上设置 dir="rtl"。逻辑间距、嵌套边框和项目内容遵循文档方向。 data-side 是物理的:left 和 right 指的是视口侧面。
HTML 结构
A3S UI maps shadcn/ui's sidebar composition to regular navigation HTML: an <aside> root, one <nav>, optional header/footer regions, grouped lists, item controls, and native <details> for nested menus.
<aside class="sidebar">Sidebar root. Supports
id,data-side="left|right",data-initial-open="false",data-initial-mobile-open="true", anddata-breakpoint. JavaScript managesaria-hidden,inert, and the internaldata-sidebar-initializedflag.<nav aria-label="...">Navigation landmark inside the sidebar.
<header>- Optional header for branding, workspace controls, user controls, or persistent actions.
<section>Scrollable content region between the optional header and footer.
<div role="group" aria-labelledby="...">- Named navigation group. Use a heading element as the group label.
<ul>+<li>Menu and menu item structure. Top-level lists and nested submenu lists receive different spacing and borders.
<a>/<button>- Menu item control. Use links for navigation and buttons for actions. Supports
data-variant="default|outline",data-size="default|sm|lg",data-active="true",disabledon buttons, andaria-disabled="true"on custom-disabled controls. For links, prefer<a aria-current="page">for the current page. Adddata-keep-mobile-sidebar-openon a clicked link, button, or ancestor when that control should not close the mobile sidebar. <details>/<summary>- Native disclosure for collapsible submenus. Put the nested
<ul>directly after<summary>. The<summary>supports the same active, variant, and size attributes as menu item controls. Addidandaria-controlswhen the relationship is not obvious from nearby markup. <hr role="separator">- Optional separator between groups or menu sections.
<footer>- Optional footer for account controls, status, or persistent actions.
<main>- Sibling content wrapper. The desktop margin applies to the sibling immediately after the sidebar.
在 :root 或侧边栏根上设置 --sidebar-width 和 --sidebar-mobile-width 以覆盖默认的 16rem 桌面宽度和 18rem 移动设备宽度。
桌面端和移动端的打开状态会在 data-breakpoint 两侧独立保存。打开移动抽屉时,焦点会进入第一个导航控件;按 Escape 或点击遮罩会关闭抽屉,并把焦点返回触发控件。普通的移动导航操作会关闭抽屉,但不会把焦点移回之前的页面位置。