Sidebar
A navigation column with a header, a scrolling body of groups and rows, and a footer. This site’s navigation is one.
Usage
import {
Sidebar,
SidebarContent,
SidebarGroup,
SidebarGroupLabel,
SidebarItem,
SidebarItemButton,
SidebarItemIcon,
SidebarItemLabel,
} from 'nyctoui/sidebar'
<Sidebar aria-label="Main">
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel>Workspace</SidebarGroupLabel>
<SidebarItem>
<SidebarItemButton render={<DocLink to="/inbox" />}>
<SidebarItemIcon><IconInbox size={16} /></SidebarItemIcon>
<SidebarItemLabel>Inbox</SidebarItemLabel>
</SidebarItemButton>
</SidebarItem>
</SidebarGroup>
</SidebarContent>
</Sidebar>The sidebar fills the height it is given, so size it from the layout around it. A router link that sets aria-current="page" marks its row as current without any extra props.
To lay a page out around it, with a resizable, collapsible edge and a drawer on narrow screens, pass it to a Sidebar Layout.
Good for
- The main navigation of a SaaS app, with groups like Workspace and Projects.
- Mailboxes and labels in an email client.
- Channels and direct messages in a team chat app.
- A docs site’s page list, like this one.
Anatomy
<Sidebar>
<SidebarHeader />
<SidebarContent>
<SidebarGroup>
<SidebarGroupLabel />
<SidebarItem>
<SidebarItemButton>
<SidebarItemIcon />
<SidebarItemLabel />
</SidebarItemButton>
<SidebarItemActions />
</SidebarItem>
<SidebarGroupEmpty />
</SidebarGroup>
</SidebarContent>
<SidebarFooter />
</Sidebar>Examples
Row actions
SidebarItemActions stay hidden until the row is hovered, a control in them is focused, or their menu is open. On touch screens they always show. Labels too long for the row fade out and slide into view on hover.
Full sidebar
A header, groups with labels, a tree of folders with menus, an empty group and a footer, in a flush sidebar beside the page.
Best practices
- Group rows under
SidebarGroupLabelheadings so people can scan for where they’re going. - Mark the current page with
active, which also setsaria-currentfor screen readers. - Keep labels short, one or two words, so they fit without truncating.
- Keep row actions, like a “More” button, for actions on that row.
- Repeat the app’s name and logo in the sidebar header when a top bar already shows them.
- Use sidebar rows to filter the content on the page. Use a segmented control or filter buttons.
API reference
Sidebar
An <aside> column. Give it an aria-label when the page has more than one.
| Prop | Type | Default |
|---|---|---|
variantflush sits on the page; floating is a rounded card with its own surface. | 'flush' | 'floating' | 'flush' |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarHeader
A 48px row at the top. Inside a Sidebar Layout it leaves its first slot to the layout’s toggle.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarContent
The scrolling middle, a ScrollArea. Content fades at whichever edge has more to scroll to.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarFooter
Pinned below the content.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarGroup
A stack of rows.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarGroupLabel
A small heading for a group.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarGroupEmpty
A note shown in a group with nothing in it yet.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarItem
One row. Draws the hover and current background around its button and actions.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarItemButton
The row’s main target, stretched over the whole row. A <button> by default.
| Prop | Type | Default |
|---|---|---|
activeMarks the row as the current page with aria-current. | boolean | — |
renderMakes the row a link, e.g. render={<DocLink to="/inbox" />}. | ReactElement | function | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarItemIcon
A fixed 20px square so labels line up.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarItemLabel
Text that never wraps.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
SidebarItemActions
Trailing controls, revealed on hover or focus. Give icon-only buttons an aria-label.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |