Sidebar example

A responsive navigation shell.

The local active view changes through the same sidebar on desktop and narrow containers.

Complete React client module · MIT · Next.js and Vite

Interactive example

A responsive navigation shell

The local active view changes through the same sidebar on desktop and narrow containers.

Loads this example when you need it.

Keyboard

  • Tab reaches the navigation trigger and named destinations.
  • Escape dismisses mobile navigation.

States covered

  • Expanded
  • Collapsed
  • Mobile drawer
  • Active view

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-basic-sidebar.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import {useState} from 'react';
import {FileText,FolderOpen} from 'lucide-react';
import {Sidebar,SidebarGroup,SidebarHeader,SidebarInset,SidebarMenuButton,SidebarProvider,SidebarTrigger,UIProvider} from '@bld8/ui';
import '@bld8/ui/styles.css';
export default function SidebarExample(){const [view,setView]=useState('projects');return <UIProvider><SidebarProvider style={{minHeight:260}}><Sidebar label="Example workspace navigation"><SidebarHeader>Example workspace</SidebarHeader><SidebarGroup label="VIEWS"><SidebarMenuButton label="Example projects" icon={FolderOpen} active={view==='projects'} onClick={()=>setView('projects')}/><SidebarMenuButton label="Example notes" icon={FileText} active={view==='notes'} onClick={()=>setView('notes')}/></SidebarGroup></Sidebar><SidebarInset><SidebarTrigger/><h3>{view==='projects'?'Example projects':'Example notes'}</h3><p>Content remains local to this module.</p></SidebarInset></SidebarProvider></UIProvider>;}