Components
Sidebar
Navigation column with sections, nested items, a header and a footer that becomes a drawer below 900px.
import { Sidebar } from "@openperf/deft";
<Sidebar.Provider>
<Sidebar.Trigger />
<Sidebar.Root>
<Sidebar.Content>
<Sidebar.Item active={true} href="/errors">
Errors
</Sidebar.Item>
<Sidebar.Item href="/traces">Traces</Sidebar.Item>
</Sidebar.Content>
</Sidebar.Root>
</Sidebar.Provider>;When to use
| Need | Component |
|---|---|
| Top-level destinations of the app | Sidebar |
| Views inside one page | Tabs |
| Path to the current page | Breadcrumb |
| List of actions opened on demand | Menu |
Anatomy
<Sidebar.Provider>
<Sidebar.Trigger /> {/* shown below 900px */}
<Sidebar.Root>
<Sidebar.Header>
<Sidebar.Pill /> {/* switcher button */}
</Sidebar.Header>
{/* scrolls */}
<Sidebar.Content>
<Sidebar.Section>
<Sidebar.Caption />
<Sidebar.Item />
</Sidebar.Section>
</Sidebar.Content>
{/* pinned to the bottom */}
<Sidebar.Footer>
<Sidebar.Item />
<Sidebar.User />
</Sidebar.Footer>
</Sidebar.Root>
</Sidebar.Provider>Sidebar.Provider holds the drawer state that Sidebar.Root and Sidebar.Trigger share. Shell.Root already includes one: inside a Shell, leave it out and put Sidebar.Trigger in the page header, or render Shell.Bar. A Sidebar.Section without a Sidebar.Caption gets extra space above it instead.
Drawer
| Viewport | Behaviour |
|---|---|
≥ 900px | Sticky column 232px wide and as tall as the viewport. Sidebar.Trigger is hidden. |
< 900px | The column is hidden. Sidebar.Trigger opens the same children in a modal drawer that slides in from the left. |
The drawer closes when an item is clicked, on Escape, on a press outside it, and when the viewport grows past 900px. An onClick passed to Sidebar.Trigger runs before the drawer opens; call event.preventDefault() in it to keep the drawer closed.
Items
Sidebar.Item is a link 28px tall whose label is cut with an ellipsis. Pass render to use a router link, a button or the trigger of another component:
<Sidebar.Item icon={IconSettings} render={<Link to="/settings" />} trailing={12}>
Settings
</Sidebar.Item>| Current page | Behaviour |
|---|---|
active | You decide, for example from the pathname so an item stays selected on its child pages. |
aria-current="page" | The link decides. Ignored once active is passed, even as false. |
icon takes a Tabler icon component, not an element, and is hidden from assistive technology. trailing holds a count, a chevron or a Kbd hint.
Header and footer
Sidebar.Pill and Sidebar.User add a selector icon after their content and are built as triggers of a Menu: a workspace switcher in the header, the user menu in the footer.
Nested items
level indents an item by one or two steps; set parent on the item above them to keep it in the default text color. Sidebar does not expand or collapse anything: render only the children that should be visible.
API
Sidebar.Root sets a localized aria-label "Navigation" unless you pass one. Sidebar.Trigger accepts the props of Button and defaults to variant="ghost", shape="square" and a localized aria-label "Open navigation".
Sidebar.Item
Prop
Type
Sidebar.Pill & Sidebar.User
Prop
Type