Components

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

Do
  • Group rows under SidebarGroupLabel headings so people can scan for where they’re going.
  • Mark the current page with active, which also sets aria-current for 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.
Don’t
  • 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

An <aside> column. Give it an aria-label when the page has more than one.

PropTypeDefault
variant
flush sits on the page; floating is a rounded card with its own surface.
'flush' | 'floating''flush'
sx
StyleX 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.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarContent

The scrolling middle, a ScrollArea. Content fades at whichever edge has more to scroll to.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarFooter

Pinned below the content.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarGroup

A stack of rows.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarGroupLabel

A small heading for a group.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarGroupEmpty

A note shown in a group with nothing in it yet.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarItem

One row. Draws the hover and current background around its button and actions.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarItemButton

The row’s main target, stretched over the whole row. A <button> by default.

PropTypeDefault
active
Marks the row as the current page with aria-current.
boolean—
render
Makes the row a link, e.g. render={<DocLink to="/inbox" />}.
ReactElement | function—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarItemIcon

A fixed 20px square so labels line up.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarItemLabel

Text that never wraps.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SidebarItemActions

Trailing controls, revealed on hover or focus. Give icon-only buttons an aria-label.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—