Skip to Content
zjkm-ui
Components

Collapsible Sidebar

A sidebar that collapses to icons.

Props
<CollapsibleSidebar items={items} current="#inbox" />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/collapsible-sidebar.json
import { CollapsibleSidebar } from "@/components/collapsible-sidebar"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

A sidebar that collapses to icons with the button at its foot. Collapsed, each label stays as its link's accessible name and shows as a tooltip on hover.

import { HugeiconsIcon } from "@hugeicons/react";
import { Home01Icon, InboxIcon } from "@hugeicons/core-free-icons";
import { CollapsibleSidebar } from "@/components/collapsible-sidebar";

const items = [
  { label: "Home", href: "/", icon: <HugeiconsIcon icon={Home01Icon} size={18} /> },
  { label: "Inbox", href: "/inbox", icon: <HugeiconsIcon icon={InboxIcon} size={18} /> },
];

export function AppSidebar({ path }: { path: string }) {
  return <CollapsibleSidebar items={items} current={path} />;
}

Props

PropTypeDefaultDescription
items{ label, href, icon }[]The links.
currentstringThe current page's href, marked with aria-current.
labelstring"Main"Accessible name of the nav.
defaultCollapsedbooleanfalseStart collapsed.
classNamestringClasses for the root element.

With reduced motion, it collapses without animating its width.

On this page