Skip to Content
kindui

Thread List

List past chats by date, so people can open, rename, pin or delete one.

Use a thread list beside a conversation to move between chats. Each chat is a link, grouped under Pinned, then by when it last changed, with a More button that opens its menu. New chat sits above the list.

Press a chat to open it, or press its More button to rename, pin or delete it. Focus a chat and press F2 to rename it in place, or the arrow keys to move between chats.

Installation

npx shadcn@latest add @kind-ui/thread-list

Composition

ThreadList
├── ThreadListNew
├── ThreadListViewport
│   ├── ThreadListGrid
│   │   ├── ThreadListHeading
│   │   └── ThreadListRow
│   │       └── ThreadListLink
│   └── ThreadListEnd
│       └── ThreadListRetry
├── ThreadListMenu
│   └── ThreadListMenuContent
└── ThreadListDialog
    ├── ThreadListDialogError
    ├── ThreadListDialogCancel
    └── ThreadListDialogDelete

ThreadList renders these parts when you pass no children: a nav named by its label. ThreadListNew is the New chat button. ThreadListViewport scrolls the rows, and ThreadListGrid renders a ThreadListHeading for each group and a ThreadListRow for each chat in view. A row holds the chat's ThreadListLink, with its title, status and unread marks, how long ago it changed, and its More button. Pass a row a function of its link's { value, title }, defined once outside a render, to replace what its link shows. ThreadListEnd shows after the rows while older chats load. ThreadListMenu is UI SDK's Menu, one for every row, and ThreadListDialog is the Alert Dialog that asks before a delete.

Usage

Threads

Pass threads, each with an id and a title, and optionally an href, an updatedAt (an ISO date-time), pinned, a group, a status and unread. With an href, a chat's row is a real link, so it opens in a new tab like any other. A status of running, awaiting-input or error shows the status mark, named "Running", "Needs input" or "Failed", and unread shows a dot named "Unread". A long title is cut short with an ellipsis, and the link's name is the whole title.

Each row ends in how long ago its updatedAt was, in a few characters: "now", "5m", "2h", "3d", then the date, like "Nov 2". The time is for the eye only, since the row's group already says when, so a screen reader reads the title alone. On hover, on focus and while its menu is open, the row's More button takes the time's place, and on touch screens More always shows instead.

Pass the current chat's id as value, and its link gets aria-current="page". You own value, as your router owns the route.

Groups

Pinned chats come first, under Pinned. Then chats with a group gather under it, in the order each group first appears, like a project or a folder. The rest gather by updatedAt: Today, Yesterday, Previous 7 days, Previous 30 days, then each month this year, then each year. Inside a group, chats keep the order you pass.

Groups and times depend on the clock, so pass now (an ISO date or date-time) when the server renders the list, or its markup and the browser's may group the chats apart. Without now, server markup shows each row's date, and the browser counts from its own clock once the list mounts, again each minute. Set timeZone to decide which day a chat falls on (UTC by default), locale for the month and year names, and groupLabels to replace the fixed words, like { today: "Aujourd'hui" }.

Opening a Chat

A plain click on a link, or Enter, calls onSelect with the chat's id. Call details.cancel() to route inside your app instead; otherwise the link follows its href. A click with a modifier key opens the link elsewhere and doesn't call onSelect.

<ThreadList
  threads={threads}
  value={chatId}
  onSelect={(id, details) => {
    details.cancel();
    router.push(`chats/${id}`);
  }}
/>

Pass onNew to show New chat, which calls it with details.source saying how it was pressed. Adding the chat and opening it is yours to do.

The Row Menu

The More button opens the row's menu, and so do a right-click or a long press on its link, Shift+F10 and the context-menu key. It offers Rename with onRename, Pin or Unpin with onPinChange, Share with onShare and Delete with onDelete, each only while its callback is set. Without any of them, rows have no More button.

Rename turns the title into a text field. Enter saves and Escape cancels, and an empty title doesn't save. onRename gets the chat's id and details.title, and the row keeps showing your title until you change it. Return a promise to keep renaming locked until it settles; a rejection is announced as "Chat not renamed". F2 on a focused link renames it too.

Pin and Unpin call onPinChange with what the chat should become in details.pinned. Share calls onShare.

The menu opens as a popover beside the More button. With presentation="auto", the default, it's a bottom sheet on small touch screens; pass "popover" or "sheet" to choose one. Under prefers-reduced-motion, or with motion="reduced", it only fades, and with motion="none" it opens at once.

Deleting

Delete opens a dialog that asks "Delete chat?" with the chat's title, focused on Cancel. Only the dialog's Delete calls onDelete, with details.source. Return a promise to keep the dialog open until it settles, with both answers disabled and Escape waiting. When it resolves, the dialog closes. A rejection keeps it open with "Couldn't delete. Try again." beside the answers, and screen readers hear "Chat not deleted".

Set confirmDelete={false} to skip the dialog when you offer Undo instead. Either way, once the chat leaves threads, focus moves to the next row, else the one before it, else New chat.

Keyboard

The list is one Tab stop. Up Arrow and Down Arrow move between chats, skipping headings, and Left Arrow and Right Arrow move between a chat's link and its More button, mirrored in right-to-left. Home and End go to either end of the row, Ctrl+Home and Ctrl+End (Cmd on a Mac) to the first and last chat, and Page Up and Page Down by a screenful. Typing the first letters of a title moves to it.

Long Histories

Only the rows in view render, at a fixed height of --kind-thread-row-height (36px), so a list of thousands scrolls like a short one. Set hasMore and pass onLoadMore to load older chats: it's called once as the list nears its end, with details.reason set to end-reached. While they load, set status="loading" to show "Loading more chats" after the rows. If loading fails, set status="error" to show "Couldn't load more chats" and Retry, which calls onLoadMore again with retry-press.

API Reference

Prop

Type

Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:

ReactVueSvelteSolid
onSelect@selectonSelectonSelect
onNew@newonNewonNew
onRename@renameonRenameonRename
onPinChange@pin-changeonPinChangeonPinChange
onShare@shareonShareonShare
onDelete@deleteonDeleteonDelete
onLoadMore@load-moreonLoadMoreonLoadMore

Agent

An agent connected with createAgent finds the list by its label and reads value, the current chat. It lists the chats by id and title, and every action takes a chat's id, refusing an unknown one. Each action is offered only while its callback is set, and rename also only while no rename is pending. select calls onSelect and follows the link unless it's cancelled. delete opens the same dialog a person sees, whose Delete always needs a person to confirm, unless the host's allow lets it through; with confirmDelete off it calls onDelete at once.

Prop

Type

Runs in React, Vue, Svelte, Solid and Web Components. On <kind-thread-list>, set threads as a property, and props are kebab-case attributes, so confirmDelete is confirm-delete. Each callback needs its attribute (can-select, can-new, can-rename, can-pin, can-share, can-delete, can-load-more) and fires an event: threadselect, threadnew, threadrename, pinchange, threadshare, threaddelete and loadmore. In a threadrename or threaddelete listener, call event.detail.waitUntil(promise) to hold the rename or keep the dialog open.