Skip to Content
Neshel-UI
Components

Sidebar

Application navigation with groups, items, collapsible sections, an icon rail and a mobile drawer.

Client component ("use client")

Purpose

Sidebar holds application navigation. Inside an AppShell it collapses on desktop and becomes a drawer on mobile; on its own it renders statically expanded.

Import

import.tsx
import {
  Sidebar,
  SidebarContent,
  SidebarFooter,
  SidebarGroup,
  SidebarHeader,
  SidebarItem,
  SidebarSeparator,
  SidebarSub,
  SidebarTrigger,
} from "@neshel-ui/components";

Usage

Inside an AppShell (see the full demo on AppShell); on its own:

Preview: sidebar-static
Preview theme
sidebar-static.tsx
import {
  Sidebar,
  SidebarContent,
  SidebarGroup,
  SidebarHeader,
  SidebarItem,
} from "@neshel-ui/components";
import { Text } from "@neshel-ui/typography";
import { FileText, Inbox } from "lucide-react";

/** Outside an AppShell a Sidebar renders statically expanded (no drawer, no collapse). */
export default function SidebarStatic() {
  return (
    <Sidebar
      aria-label="Mailbox"
      className="!h-auto max-w-64 rounded-lg border border-[var(--neshel-border)]"
    >
      <SidebarHeader>
        <Text weight="semibold">Mail</Text>
      </SidebarHeader>
      <SidebarContent aria-label="Folders">
        <SidebarGroup label="Folders">
          <SidebarItem active icon={<Inbox aria-hidden="true" />}>
            Inbox
          </SidebarItem>
          <SidebarItem icon={<FileText aria-hidden="true" />}>Drafts</SidebarItem>
        </SidebarGroup>
      </SidebarContent>
    </Sidebar>
  );
}

API

SidebarProps

SidebarProps
PropTypeDefaultDescription
closeLabelstring"Close navigation"Accessible name of the drawer's close button (default "Close navigation").
collapsedboolean—Collapsed state for a sidebar used outside an AppShell.
collapsibleSidebarCollapsible—What collapsing does on desktop: icon rail (default), hide completely, or nothing.
mobileTitlestring"Navigation"Accessible title of the mobile drawer (default "Navigation").
refRef<HTMLElement>——

Also accepts the props of: React DOM attributes.

SidebarCollapsible

type SidebarCollapsible = "icon" | "offcanvas" | "none"

SidebarPartProps

SidebarPartProps
PropTypeDefaultDescription
refRef<HTMLDivElement>——

Also accepts the props of: React DOM attributes.

SidebarGroupProps

SidebarGroupProps
PropTypeDefaultDescription
labelReactNode—Visible group heading; labels the list (visually hidden in the rail).
refRef<HTMLDivElement>——

Also accepts the props of: React DOM attributes.

SidebarItemProps

SidebarItemProps
PropTypeDefaultDescription
activeboolean—The current page: aria-current="page" on links, data-active always.
asChildboolean—Render the single child (a link or router link) as the item.
iconReactNode—Decorative icon (shown alone in the rail).
refRef<HTMLButtonElement>——
tooltipstring—Rail tooltip text (default: the label when it is a string).
type"button" | "submit" | "reset""button"Button type when no asChild child is given (default "button").

Also accepts the props of: React DOM attributes.

SidebarSubProps

SidebarSubProps
PropTypeDefaultDescription
childrenReactNode——
classNamestring——
defaultOpenboolean——
iconReactNode—Decorative icon; in the collapsed rail it is the only visible content.
label(required)ReactNode—Visible label of the collapsible group trigger.
onOpenChange(open: boolean) => void——
openboolean——

SidebarTriggerProps

SidebarTriggerProps
PropTypeDefaultDescription
labelstring"Toggle sidebar"Accessible name when no children are given (default "Toggle sidebar").
refRef<HTMLButtonElement>——

Also accepts the props of: React DOM attributes.

PartRenders
Sidebar<aside> (aria-label "Sidebar"); collapsible, mobileTitle
SidebarHeader / SidebarFooterdivs at the top and bottom
SidebarContent<nav aria-label="Main navigation">
SidebarGroupA labelled list (label)
SidebarItem<button> by default, or your link with asChild; icon, active, tooltip
SidebarSubA collapsible group of items (label, icon, open/defaultOpen/onOpenChange)
SidebarSeparatorA divider
SidebarTriggerToggles collapse on desktop and the drawer on mobile (label "Toggle sidebar")

Full and collapsed

  • collapsible="icon" (default): collapsing shows an icon rail. Labels remain the accessible names and appear as tooltips on hover and focus.
  • collapsible="offcanvas": collapsing hides the sidebar on desktop.
  • collapsible="none": always expanded on desktop.

Widths: --neshel-sidebar-width (default 16rem) and --neshel-sidebar-rail-width (3.5rem).

Accessibility

  • active sets aria-current="page" on the current item.
  • SidebarTrigger exposes aria-expanded and aria-controls for the current mode.
  • In the drawer, focus is trapped and returns to the trigger; activating a link closes the drawer.

Keyboard

KeyAction
TabMove through items
Enter / SpaceActivate an item, expand a SidebarSub
Escape (drawer)Close the drawer

Limitations

  • Children remount between desktop and mobile. The sidebar content renders exactly once — inline on desktop, inside the drawer on mobile — never both. When the mode changes (resizing across the breakpoint, or opening the drawer on mobile), React unmounts the children from one host and mounts them in the other. Component-local state inside the sidebar is reset (an uncontrolled SidebarSub returns to defaultOpen, a text field loses its draft, effects run again). Keep state that must survive in a parent (controlled open on SidebarSub, values in your store) and make effects idempotent.
  • The drawer is not rendered during server rendering; mobile users see the trigger first.

Common mistakes

  • Persisting the collapsed state in localStorage read during render (hydration mismatch): use a cookie and defaultCollapsed.
  • Icon-only content in items without text: the rail needs the text as the accessible name.
Edit on GitHub

On this page