shadcn.io is not affiliated with official shadcn/ui
Recent Items Command Menu Block for React
A project hub's command menu shown open on what you opened lately: Today, Yesterday and Earlier buckets before you type, recent matches first when you do, opening a row moves it to the top, and a last row clears the list.
Installation
Overview
Pick up where you left off with this recent items command menu for React with Base UI. It opens from the Projects page of Tracemill, a hub for a team's projects, docs and boards, whose header holds an outline field with its ⌘ K cap, and the page is drawn under a soft scrim inside a hairline frame with a plus mark on each corner. The menu is the catalog Command. With the input empty it lists what you opened lately in three buckets, Today, Yesterday and Earlier, each row with its type as a word; start typing and it looks through everything, with the recent matches first and tagged with a Badge that says Recent, and the letters that match marked with Search Highlight Text. Opening a row moves it to the top of Recent, in the Today bucket, and a last row, Clear recents, empties the list to a line that says nothing was opened yet. The drawn project list behind the menu says which was opened last, and the status line says what the choice did. For preview the menu is drawn open in place when the page loads; the field, or Ctrl or ⌘ K while focus is in the block, opens the real command dialog with the same recents and the same query. For project tools, document hubs, admin consoles and any app people return to the same few things in.
FAQ
Why is the menu already open, and what do I keep?
So you can see it without a click. On load the menu is the Command drawn inline over a picture of the project list, in a plain shell that is not modal, so nothing is trapped, hidden or focused and the page around the preview keeps working. The header's field opens the real command dialog, modal, with its focus trap, Escape and focus return, and the inline copy stays closed until a reload. Both show the same Palette and share the block's state, so the recents and the text you typed in the copy are in the real dialog. In your app keep the dialog and drop the copy: the "in-place" state, the scrim with its shell and the Escape and blur effects.
How do the recents work, and where would they come from?
rowsFor(query, seen) is a plain function from the query and the list of what was opened to the rows. With the input empty it buckets that list by day; with a query it keeps the items whose title, type or hidden keywords hold it, ignoring case and accents, and puts those you opened first. Opening a row puts it first in the list, marked as opened today. Here the list lives in state; in your app keep it in local storage or on the server, per person, and trim it to the last dozen or so.
What does Clear recents do, and can I undo it?
It empties the list in this demo, says how many it cleared in the status line and leaves the menu open on the empty state, which tells you to type to search everything. There is no undo here; reload the page to get the list back. In your app, ask first if the list holds anything people pinned.
What stays local, and how do I wire it up?
Everything. Choosing a row moves it to the top of the list and the drawn project list names it; nothing opens. In your app replace ITEMS with your search index and, in pick, send the person to the item and record the open.
Is it accessible from the keyboard?
Yes. Type to search, the arrow keys move through the rows, Enter opens the highlighted one and Escape closes the menu and puts focus on the field; Ctrl or ⌘ K opens the dialog while focus is inside the block, and only then. The rows are options of a cmdk listbox; the block turns off its own fuzzy filter and lists the rows itself. The real dialog is named by its title and described by its sentence.
Related
- Pro
Version History Command Menu
Actions and keysA design editor's command menu shown open at the end of the editor: twelve things done in four time buckets, type chips that filter them, choosing an entry reverts it and the drawn layer list follows, and Clear history asks before it clears.
- Pro
Basic Command Menu
Search everythingA team workspace's home page with its command menu shown open: eleven pages in three groups, a shortcut on the five most used, matches marked, an empty state that says what to try and a foot with the key hints and a spoken count.
- 333Pro
Global Search Command Menu
Search everythingA company intranet's command menu shown open: one input searches pages, docs, people and tags at once, each type is a group of three matches with a row that opens it in place, and the foot counts the results by type.
- Pro
Docs Tree Command Menu
Pages and docsAn API docs host's page finder as a command menu shown open on a tree: sections open into indented pages with the arrow keys, typing flattens the tree and matches the headings inside pages, and the foot counts the open sections.
- Pro
Command Palette Dialog
Pickers and searchA docs workspace's command palette shown open over its page: Recent and Pages when the field is empty, and a typed greater-than, at or hash turns it to Actions, People or Pages, each with its own groups and count, and each choice edits the drawn page.
- Pro
Command Palette FAQ
SearchA FAQ for a docs host with a working command palette: a search-field button with its shortcut opens a palette of questions by topic, and choosing one opens its row below.