```
`rui-sidebar-trigger` stamps `[data-ref="button"]` and syncs `aria-expanded` / `aria-controls` against the sidebar.
Each trigger also reflects its controlled sidebar's state, mobile mode, and collapse mode on the trigger host. An explicit `controls` id targets only that `rui-sidebar`; if it does not resolve, the trigger stays unattached and does not toggle a nearby sidebar. Without `controls`, a trigger inside a sidebar uses that ancestor. Placement and glyph styles read only the trigger host and its `placement` attribute, so an attached trigger follows the sidebar's `mobileBreakpoint` rather than the viewport width, including when providers are nested.
Before a trigger attaches (the server-rendered paint), placement styles treat viewports below 768px as mobile and read the sidebar whose pane holds the trigger, else the only sidebar of its nearest provider (child combinators, so nested providers stay independent). Other triggers, such as inset triggers shared by two sidebars in one provider, stay visible until they attach.
## Collapsible modes
`icon` collapses to icons only. `full` hides the sidebar entirely. `off` keeps it always visible.
## Active route matching
Enable `matchActive` with `matchMode` to highlight the current page in the menu automatically.
## Theming
Sidebar surfaces map to **semantic surface roles**, never Tailwind palette steps:
| Part | CSS roles |
| --- | --- |
| Pane (`rui-sidebar`) | `background` |
| Header / content / footer | `border` between sections |
| Menu buttons | `on-background` text |
| Active menu button | `primary` indicator |
| Resize handle | `border` + `on-surface` grip, `primary` on hover |
| Inset | `background` |
Rounded corners use `rounded-container`; the collapsible pane in `docs` layout sits on `surface-container-low`. Overrides go at the theme layer, not in component CSS.
## Accessibility
- The sidebar renders as a `nav` landmark with `label` as its accessible name.
- Collapsed icon-only mode preserves accessible names on menu buttons.
- The trigger button exposes whether the sidebar is expanded or collapsed.
## API
`RuiSidebar` (``) coordinates the pane, resize, collapse, and active-route matching. Compose sections with the view helpers; `RuiSidebarProvider` wires the shell.
### Attributes (``)
| Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `sidebar` · `inset` · `floating` | `sidebar` | Pane treatment. |
| `side` | `left` · `right` | `left` | Which side the pane sits on. |
| `collapsible` | `off` · `icon` · `full` | `off` | Collapse behavior. |
| `defaultWidth` | `number` | | Initial width in px. |
| `width` | `number` | | Controlled width. |
| `minWidth` / `maxWidth` | `number` | | Width bounds. |
| `resizable` | `boolean` | `false` | Draggable resize handle. |
| `defaultOpen` | `boolean` | `true` | Initial open state (desktop). |
| `mobileDefaultOpen` | `boolean` | `false` | Open state on mobile when uncontrolled (mount and when the viewport crosses into mobile). |
| `open` | `boolean` | | Controlled open state. Viewport crossings do not override this. |
| `mobileBreakpoint` | `number` | | Width below which the mobile rail applies. |
| `label` | `string` | `Sidebar` | Accessible name for the `nav` landmark. |
| `matchActive` | `boolean` | `false` | Highlight the current route in the menu. |
| `matchMode` | `pathname` · … | `pathname` | Route matching mode. |
| `scrollActiveOnMount` | `boolean` | `false` | Scroll the active item into view on mount. |
| `navigationEvents` | `string` | `''` | Custom navigation events to listen for. |
### Light-DOM contract (``)
| Target | Required | Host writes | Author owns |
| --- | --- | --- | --- |
| `[data-ref="root"]` | yes | `data-state`, `data-collapsible`, … | inner shell |
| `[data-ref="pane"]` | yes | `aria-label`, `inert` | pane content |
| `[data-ref="scrim"]` | no | `hidden` | mobile overlay button |
| `[data-ref="handle"]` | no | `hidden`, `aria-valuenow`, … | resize handle |
| `[data-ref="menu-button"]` | no | `aria-current`, active class | menu links |
Host-owned on ``: `role="complementary"`, `data-state`, `data-pane-width`, …
### Methods (``)
| Method | Description |
| --- | --- |
| `toggle()` | Open or close the pane. |
| `setOpen(next)` | Set open state. |
| `syncActiveLinks(scroll?)` | Match menu links to the current location when `matchActive` is set. |
### Light-DOM contract (``)
| Target | Required | Host writes | Author owns |
| --- | --- | --- | --- |
| `[data-ref="button"]` | yes | `aria-expanded`, `aria-controls`, `aria-label`; swaps `rui-button--{variant}` / `--{size}` | toggle button and its other classes |
### Attributes (``)
| Attribute | Type | Default | Description |
| --- | --- | --- | --- |
| `controls` | `string` | `''` | Exact sidebar id. An unresolved id does not fall back to an ancestor sidebar. |
| `button-label` | `string` | `Toggle sidebar` | Accessible trigger name (`triggerLabel` on `RuiSidebarTrigger`). |
| `placement` | `''` · `header` · `inset` | `''` | Trigger placement; reflected for placement styles. |
| `variant` | `ghost` · … | `ghost` | Button tone (reuses `RuiButton` variants). |
| `size` | `sm` · `md` · `lg` | `md` | Button size. |
The host writes `data-sidebar-state`, `data-sidebar-mobile`, and `data-sidebar-collapsible` on ``. `data-sidebar-mobile` and `data-sidebar-collapsible` appear once the trigger attaches to its sidebar. Until then, `data-sidebar-state` matches the server render: `collapsed` for `inset`, `expanded` otherwise.
### Events
| Event | Detail | Description |
| --- | --- | --- |
| `rui-sidebar-toggle` | | Emitted on every open/closed transition. |
| `rui-sidebar-resize` | `{ width }` | Emitted on every width change. |
| `rui-sidebar-mobile-change` | | Emitted when the host flips mobile rail state. |
### View helpers
| Component | Target stamped | Notes |
| --- | --- | --- |
| `RuiSidebarProvider` | — | Shell (`data-layout`) wrapping sidebar + inset. |
| `RuiSidebarHeader` / `RuiSidebarContent` / `RuiSidebarFooter` | — | Pane sections; not queried. |
| `RuiSidebarSeparator` | — | Horizontal rule. |
| `RuiSidebarGroup` / `RuiSidebarGroupLabel` / `RuiSidebarGroupAction` / `RuiSidebarGroupHeader` | — | Grouped items. |
| `RuiSidebarMenu` / `RuiSidebarMenuItem` | — | Menu list + item wrappers. |
| `RuiSidebarMenuButton` | `[data-ref="menu-button"]` on `` or `