| title | Sidebar |
|---|---|
| description | A collapsible side navigation panel component. |
| source | packages/raystack/components/sidebar |
import { preview, positionDemo, stateDemo, tooltipDemo, collapsibleDemo, hideTooltipDemo } from "./demo.ts";
Import and assemble the component:
import { Sidebar } from "@raystack/apsara";
<Sidebar>
<Sidebar.Header />
<Sidebar.Main>
<Sidebar.Group label="Group name">
<Sidebar.Item href="#">Item</Sidebar.Item>
</Sidebar.Group>
</Sidebar.Main>
<Sidebar.Footer />
</Sidebar>Groups all parts of the sidebar navigation. Use collapsible={false} to hide the resize handle and prevent toggling. Use hideCollapsedItemTooltip to disable tooltips on items when the sidebar is collapsed.
The header section is a container component that accepts all div props. It's commonly used to create a header with an icon and title.
The main section wraps navigation groups and items. It accepts all div props and scrolls when content overflows.
Note: leadingIcon is optional and will show a fallback avatar only in collapsed state. You can pass <></> to render truly nothing. Use the as prop to render as a custom element (e.g. a router Link).
The footer section is a container that accepts all div props. It's commonly used for secondary links (e.g. Help, Preferences) and stays at the bottom of the sidebar.
The Sidebar can be positioned on either the left or right side of the screen.
The Sidebar supports expanded and collapsed states with smooth transitions.
The data-collapse-hidden attribute can be used to conditionally hide elements when the sidebar is collapsed.
You can customize the tooltip message that appears when hovering over the collapse/expand handle using the tooltipMessage prop.
You can use Sidebar as a controlled component to conditionally render different tooltip messages.
Set collapsible={false} to hide the resize handle and prevent the sidebar from being collapsed or expanded.
Set hideCollapsedItemTooltip to disable tooltips on navigation items when the sidebar is collapsed. Useful when item labels are redundant with the collapse tooltip or you want a cleaner collapsed state.
The Sidebar implements the following accessibility features:
-
Reduced motion — Sidebar collapse/expand motion is enabled only when
prefers-reduced-motion: no-preference. -
Proper ARIA roles and attributes
role="navigation"for the main sidebarrole="banner"for the headerrole="list"for item containers (Main groups, Footer) androle="listitem"for navigation itemsaria-expandedto indicate sidebar statearia-current="page"for active itemsaria-disabled="true"for disabled items
-
Keyboard navigation support
- Enter/Space to toggle sidebar expansion
- Tab navigation through interactive elements
-
Screen reader support
- Meaningful labels for all interactive elements
- Hidden decorative elements
- Clear state indicators