Sidebar
Application navigation with groups, items, collapsible sections, an icon rail and a mobile drawer.
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 {
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:
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
| Prop | Type | Default | Description |
|---|---|---|---|
| closeLabel | string | "Close navigation" | Accessible name of the drawer's close button (default "Close navigation"). |
| collapsed | boolean | — | Collapsed state for a sidebar used outside an AppShell. |
| collapsible | SidebarCollapsible | — | What collapsing does on desktop: icon rail (default), hide completely, or nothing. |
| mobileTitle | string | "Navigation" | Accessible title of the mobile drawer (default "Navigation"). |
| ref | Ref<HTMLElement> | — | — |
Also accepts the props of: React DOM attributes.
SidebarCollapsible
type SidebarCollapsible = "icon" | "offcanvas" | "none"SidebarPartProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
SidebarGroupProps
| Prop | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | — | Visible group heading; labels the list (visually hidden in the rail). |
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
SidebarItemProps
| Prop | Type | Default | Description |
|---|---|---|---|
| active | boolean | — | The current page: aria-current="page" on links, data-active always. |
| asChild | boolean | — | Render the single child (a link or router link) as the item. |
| icon | ReactNode | — | Decorative icon (shown alone in the rail). |
| ref | Ref<HTMLButtonElement> | — | — |
| tooltip | string | — | 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
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | — |
| className | string | — | — |
| defaultOpen | boolean | — | — |
| icon | ReactNode | — | 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 | — | — |
| open | boolean | — | — |
SidebarTriggerProps
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Toggle sidebar" | Accessible name when no children are given (default "Toggle sidebar"). |
| ref | Ref<HTMLButtonElement> | — | — |
Also accepts the props of: React DOM attributes.
| Part | Renders |
|---|---|
Sidebar | <aside> (aria-label "Sidebar"); collapsible, mobileTitle |
SidebarHeader / SidebarFooter | divs at the top and bottom |
SidebarContent | <nav aria-label="Main navigation"> |
SidebarGroup | A labelled list (label) |
SidebarItem | <button> by default, or your link with asChild; icon, active, tooltip |
SidebarSub | A collapsible group of items (label, icon, open/defaultOpen/onOpenChange) |
SidebarSeparator | A divider |
SidebarTrigger | Toggles 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
activesetsaria-current="page"on the current item.SidebarTriggerexposesaria-expandedandaria-controlsfor the current mode.- In the drawer, focus is trapped and returns to the trigger; activating a link closes the drawer.
Keyboard
| Key | Action |
|---|---|
| Tab | Move through items |
| Enter / Space | Activate 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
SidebarSubreturns todefaultOpen, a text field loses its draft, effects run again). Keep state that must survive in a parent (controlledopenonSidebarSub, 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.