# Chat Sidebar

> The sidebar of a chat app, with pinned chats, projects and recents. Handles rename in place, delete with undo and chats still replying.

Canonical: https://hextaui.com/blocks/chat-sidebar
Last updated: 2026-10-29

## Overview

ChatGPT, Claude, Perplexity and Grok all settled on the same sidebar: start a chat or search from the top, keep a few chats pinned, group work into projects, and scroll back through everything else by day. Chat Sidebar is that sidebar, built on the HextaUI Sidebar’s inset variant, so the conversation sits in its own rounded panel inside the frame. It collapses to an icon rail on desktop, and on phones it slides in to fill the screen and slides away as soon as you pick a chat.

The header holds your logo, a search button and the collapse button. New chat sits below with its shortcut always visible, followed by any links you pass, such as Images, Library or Plugins. Projects are collapsible folders, each with its own icon, and their chats sit indented inside them rather than in the history. Recents group into Today, Yesterday, Previous 7 days, Previous 30 days and then by month, and render in pages as you scroll, so thousands of chats open instantly.

Every row has a menu on hover and the same menu on right-click: pin, rename, move to a project and delete. Rename happens in place with double-click or F2. Delete hides the chat at once and offers Undo for five seconds before calling onDelete. A chat that is replying shows a spinner and one that finished elsewhere shows a dot; both step aside for the menu button on hover. The account menu opens upward with your name and email on top of the items you pass in.

## Installation

### Step 1: Get HextaUI Pro

One payment unlocks every block, including future ones. [See pricing](https://hextaui.com/pricing).

### Step 2: Add the Pro registry to components.json

```json title="components.json"
{
  "registries": {
    "@hextaui-pro": {
      "url": "https://hextaui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${HEXTAUI_PRO_TOKEN}"
      }
    }
  }
}
```

### Step 3: Add your token

Create a token on your [account page](https://hextaui.com/account) and put it in `.env.local` as `HEXTAUI_PRO_TOKEN`.

### Step 4: Add the block

```bash
npx shadcn@latest add @hextaui-pro/chat-sidebar
```

## Usage

### Wire it to your state

Pass the chats and the handlers you support. Each menu item appears only when its handler is set, so a read-only history needs just onSelect and onNewChat.

```tsx
"use client"

import * as React from "react"

import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"

import { ChatSidebar } from "@/components/blocks/chat-sidebar/chat-sidebar"
import type { SidebarChat } from "@/components/blocks/chat-sidebar/chats"

export function App({ initialChats }: { initialChats: SidebarChat[] }) {
  const [chats, setChats] = React.useState(initialChats)
  const [activeId, setActiveId] = React.useState<string | null>(null)

  const update = (id: string, change: Partial<SidebarChat>) =>
    setChats((current) => current.map((chat) => (chat.id === id ? { ...chat, ...change } : chat)))

  return (
    <SidebarProvider>
      <ChatSidebar
        chats={chats}
        activeId={activeId}
        onSelect={setActiveId}
        onNewChat={() => setActiveId(null)}
        onRename={(id, title) => update(id, { title })}
        onPinnedChange={(id, pinned) => update(id, { pinned })}
        onDelete={(id) => setChats((current) => current.filter((chat) => chat.id !== id))}
        user={{ name: "Mia Chen", plan: "Pro plan" }}
      />
      <SidebarInset />
    </SidebarProvider>
  )
}
```

### Projects and routing

Each project is a collapsible folder with its own icon. Its chats sit indented inside it instead of in the dated history. onMove adds Move to project to every row.

```tsx
"use client"

import { useRouter } from "next/navigation"

import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"

import { ChatSidebar } from "@/components/blocks/chat-sidebar/chat-sidebar"
import type { SidebarChat, SidebarProject } from "@/components/blocks/chat-sidebar/chats"

export function Workspace({
  chats,
  projects,
  activeId,
  moveChat,
  children,
}: {
  chats: SidebarChat[]
  projects: SidebarProject[]
  activeId: string | null
  moveChat: (id: string, projectId: string | null) => void
  children: React.ReactNode
}) {
  const router = useRouter()

  return (
    <SidebarProvider>
      <ChatSidebar
        chats={chats}
        projects={projects}
        activeId={activeId}
        onSelect={(id) => router.push(`/c/${id}`)}
        onNewChat={() => router.push("/")}
        defaultOpenProjects={projects.slice(0, 1).map((project) => project.id)}
        onMove={moveChat}
      />
      <SidebarInset>{children}</SidebarInset>
    </SidebarProvider>
  )
}
```

## Anatomy

The parts you compose, from the outside in.

| Part | Description |
| --- | --- |
| `ChatSidebar` | The whole sidebar: header, New chat and links, pinned chats, projects, dated history and the account menu. |
| `groupChats` | Sorts chats newest first and splits them into the dated groups the sidebar shows. |
| `searchChats` | Word-based title search used by the search dialog. Returns the 8 most recent chats for an empty query. |

## API reference

### ChatSidebar

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `chats` | `SidebarChat[]` | – | Every chat, in any order. Each has id, title, updatedAt (ms) and optional projectId, pinned and status ("streaming" or "unread"). |
| `projects` | `SidebarProject[]` | `[]` | Projects with id, name and an optional icon. Each renders as a collapsible folder holding its chats. The section hides when empty. |
| `activeId` | `string \| null` | – | The open chat, marked as the current page. |
| `onSelect` | `(id: string) => void` | – | Called when a chat is chosen from the list, search or the recents card in the icon rail. |
| `onNewChat` | `() => void` | – | Called from the New chat button and ⌘⇧O. |
| `links` | `{ label, icon, href?, active?, onSelect? }[]` | `[]` | Extra rows under New chat, such as Images, Library or Plugins. They stay as icons with tooltips in the rail. |
| `defaultOpenProjects` | `string[]` | `[]` | Projects that start expanded. |
| `onProjectOpenChange` | `(id: string, open: boolean) => void` | – | Called when a project is expanded or collapsed, so you can remember it. |
| `onRename` | `(id: string, title: string) => void` | – | Enables Rename, double-click and F2. Called only when the title actually changed. |
| `onPinnedChange` | `(id: string, pinned: boolean) => void` | – | Enables Pin and Unpin. |
| `onMove` | `(id: string, projectId: string \| null) => void` | – | Enables Move to project. null removes the chat from its project. |
| `onDelete` | `(id: string) => void` | – | Enables Delete. Called after the five-second Undo window closes. |
| `brand` | `ReactNode` | – | Your logo, at the top next to the search and collapse buttons. |
| `user` | `{ name, email?, image?, plan? }` | – | Shows the account button in the footer. |
| `accountMenu` | `ReactNode` | – | DropdownMenu items under the name and email, such as Settings, a Help submenu and Log out. |
| `pageSize` | `number` | `60` | How many history rows render at a time. More load as you near the end of the list. |
| `className` | `string` | – | Classes for the Sidebar root. |

## Keyboard

| Key | Action |
| --- | --- |
| `⌘` `K` | Opens or closes chat search. The search button in the header does the same. |
| `⌘` `⇧` `O` | Starts a new chat. |
| `⌘` `B` | Collapses to the icon rail or expands. On phones, opens or closes the full-screen sidebar. |
| `F2` | Renames the focused chat. Double-click does the same. |
| `Enter` | Expands or collapses the focused project. While renaming, saves the new title; leaving the field also saves. |
| `Esc` | Cancels a rename, or closes a menu or search. |

## Accessibility

- The open chat is marked with aria-current="page", and each row’s menu button is named after its chat, such as “Options for Pricing page copy”. Reply states are announced as “Replying” and “Unread reply” rather than shown only as a spinner or dot.
- Menu buttons appear on hover for mouse users but stay reachable with Tab, and every row action is in that menu, so nothing depends on right-click or double-click. Projects report aria-expanded, and their chats stay findable with the browser’s find once a project has been opened.
- The typing title and the full-screen slide on phones respect reduced motion. Undo stays in the toast until it times out, and focus stays where it was when a chat is deleted.

## Built with

The free HextaUI components Chat Sidebar is made from. Each one installs on its own.

- [Avatar](https://hextaui.com/docs/avatar) - User photos with an initials fallback, status badges and stacked groups that collapse into a count.
- [Button](https://hextaui.com/docs/button) - Buttons in every variant and size, with a built-in loading, success and error flow that skips the spinner for fast requests.
- [Collapsible](https://hextaui.com/docs/collapsible) - A panel that shows and hides with height motion you can reverse mid-way, without jumping the layout.
- [Command](https://hextaui.com/docs/command) - A searchable list of actions, inline or as a ⌘K palette, with pages, shortcuts and highlighted matches.
- [Context menu](https://hextaui.com/docs/context-menu) - A menu of actions on right click or long press, with submenus, checkbox and radio items, and hold feedback on touch.
- [Dropdown menu](https://hextaui.com/docs/dropdown-menu) - A menu of actions and options behind a button, with groups, submenus, checkbox and radio items, and shortcuts.
- [Hover card](https://hextaui.com/docs/hover-card) - A preview card that opens when a link is hovered or focused, for content sighted users can glance at.
- [Kbd](https://hextaui.com/docs/kbd) - Key caps for shortcuts that show the right symbols on every platform, read them out properly and press down with the real keys.
- [Sidebar](https://hextaui.com/docs/sidebar) - An app sidebar that collapses to icons or off canvas, stays pinned under your header, and becomes a swipeable sheet on phones.
- [Spinner](https://hextaui.com/docs/spinner) - A loading indicator with Apple-style ticks or a breathing ring that can wait before showing and stay long enough not to flicker.
- [Toast](https://hextaui.com/docs/toast) - Brief messages that stack neatly, expand on hover, swipe away, and turn a loading state into success or error in place.
- [Tooltip](https://hextaui.com/docs/tooltip) - A short hint on hover or keyboard focus that opens after a brief rest, switches instantly between neighbours and shows shortcuts.

## Code

4 files, added to components/blocks/chat-sidebar.
