Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Search History Navbar Block for React

A navbar for a video site with a wide search that brings back your recent searches on focus, each with a clock icon and its own remove button, narrowing as you type with suggestions beneath.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

A video-site navbar for React with Base UI, the bar that keeps your searches for you. For Streamcove, a video-hosting site, the wordmark leads, a wide search field sits in the middle, and a Subscriptions link and an Upload Shine Button close the row. Focus the field and your recent searches come back first, each with a clock icon and a remove button of its own, with up to five suggestions under them; type and both groups narrow, by the words in them, ignoring case and accents, with the matching letters marked. Choosing a row, or pressing Enter on a new query, puts it at the top of the history (it keeps the last five); the X on a row removes it without leaving the field, and so does Shift and Delete on the highlighted recent search. The history lives in the block's state, so nothing is stored: reload and it starts again. Press "/" anywhere on the page that isn't a text field and the field takes focus. The popup is portalled, so the bar stays one bar high (64 pixels, 56 on a phone) while it is open. On a phone a search button replaces the bar with the field, and a menu button opens a sheet from the top with Subscriptions and Upload. It's built from Autocomplete, InputGroup, Kbd, Sheet, Shine Button and Guides with Lucide icons and your theme's tokens for every colour. For video, podcast and media sites whose visitors search the same things again.

FAQ

How do I keep the history between visits?

The history is recent in VideoSearch, seeded from START. To keep it, write the array to localStorage (or your account) whenever it changes and read it back as the initial state after mount, so the server and the browser render the same first frame. remember puts a search first without repeats and caps the list at KEPT, and remove drops one. Suggestions come from SUGGESTIONS; replace suggestionRows with your own source, fetched or local.

How do I remove a recent search, with a pointer or a keyboard?

Press the X on its row: the row goes, the popup stays open and focus stays in the field. From the keyboard, move to the row with the arrow keys and press Shift and Delete; plain Backspace and Delete keep editing the text you typed, so nothing is lost by accident. The X button is skipped by Tab because the field already offers the same action, and a polite status line says "Removed" followed by the search, so a screen reader hears it. The field points to a hidden hint that names the shortcut.

How does the narrowing work, and what does Enter do?

The rows are rebuilt from the typed text on every change: a recent search or a suggestion stays when it holds the text, and a suggestion already in your history is not listed twice. Highlighting a row with the arrow keys never rewrites what you typed. Enter on a highlighted row picks it and fills the field; Enter on text that no row is highlighted for searches it, which puts it at the top of the history. When nothing matches, the popup says so.

How does it work with a keyboard and a screen reader?

The field is a combobox with an accessible name and the popup is a listbox of options in two labelled groups, Recent and Suggestions. The arrow keys move through the rows, Enter picks one and Escape closes the popup, leaving focus in the field. The field declares the "/" key with aria-keyshortcuts, and the key cap is hidden from screen readers because it's a hint, not a control. The search sits in a search landmark and Subscriptions in a nav named Main, marked as the current page. The popup behaves the same on every library, because it is built on the same combobox everywhere.

How does it work on a phone?

Below the md breakpoint the bar shows the wordmark, a search button and a menu button. The search button says whether the search is open and which landmark it controls; pressing it (or "/") replaces the bar with the field, which takes the keyboard, and turns the button into a close button in the same place. Escape closes the popup first and ends the search second, and focus returns to the search button. The menu button opens a sheet from the top whose header lines up with the bar, with Subscriptions and an Upload button; choosing a link closes it and Escape returns focus to the menu button. Nothing wraps at 320 pixels, and the popup is never wider than the screen.

  • Pro

    A navbar for a support-desk product with a search field whose popup lists help articles and categories in two labelled groups, marks the matching letters, and offers an Ask support link when nothing matches.

  • Pro

    A navbar for an add-on store with a Categories menu of six categories and their counts, and a search whose popup lists add-ons with an icon tile, drawn stars, an install count and a category.

  • Pro

    A navbar for a legal-research database whose field-looking search button opens a panel from the top with a large input, recent searches you can remove, popular topic tags and live results with the matching letters marked.

  • Pro

    A navbar for a notes app with a field-looking button and a shortcut that open a command palette: recent notes first, then pages, actions and settings in labelled groups, with the keys that work shown beside each row.

  • Pro

    A documentation search field in a slim bar: an icon, a labelled input and a slash key hint, with a popup of results that filters as you type.

  • Pro

    A navbar for a neighbourhood network: four links with an unread count, a profile avatar and a Create post button that opens a composer with a 280-character ring and a Post button that disables over the limit.