# Sidebar

Collapsible navigation sidebar panel



<ComponentPreview base="opentui" name="sidebar-demo" />

Installation [#installation]

<CodeTabs>
  <TabsList>
    <TabsTrigger value="cli">
      Command
    </TabsTrigger>

    <TabsTrigger value="manual">
      Manual
    </TabsTrigger>
  </TabsList>

  <TabsContent value="cli">
    ```bash
    npx shadcn@latest add @termcn/opentui-sidebar
    ```
  </TabsContent>

  <TabsContent value="manual">
    <Steps>
      <Step>
        Copy and paste the following code into your project.
      </Step>

      <ComponentSource base="opentui" name="sidebar" title="components/ui/sidebar.tsx" />

      <Step>
        Update the import paths to match your project setup.
      </Step>
    </Steps>
  </TabsContent>
</CodeTabs>

Usage [#usage]

```tsx
import { Sidebar } from "@/components/ui/sidebar";
```

```tsx
<Sidebar
  title="Explorer"
  activeKey="inbox"
  items={[
    { key: "inbox", label: "Inbox", icon: "📥", badge: 3 },
    { key: "drafts", label: "Drafts", icon: "📝" },
  ]}
  onSelect={(key) => console.log(key)}
/>
```

API Reference [#api-reference]

Sidebar [#sidebar]

| Prop        | Type                    | Default    |
| ----------- | ----------------------- | ---------- |
| `items`     | `SidebarItem[]`         | `required` |
| `activeKey` | `string`                | -          |
| `onSelect`  | `(key: string) => void` | -          |
| `collapsed` | `boolean`               | `false`    |
| `width`     | `number`                | `20`       |
| `title`     | `string`                | -          |

SidebarItem [#sidebaritem]

| Prop       | Type               | Default    |
| ---------- | ------------------ | ---------- |
| `key`      | `string`           | `required` |
| `label`    | `string`           | `required` |
| `icon`     | `string`           | -          |
| `badge`    | `string \| number` | -          |
| `children` | `SidebarItem[]`    | -          |
