Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Top Bar Search Banner Block for React

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.

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 search strip for React with Base UI, the field a documentation site keeps above its pages. For Quailcraft, a documentation tool, the product's name sits at the start and a full-width field fills the rest: a search icon, an input labelled "Search the docs" and a "/" key hint at the end. The hint is decoration, but the key really works: press "/" anywhere on the page that isn't a text field and the field takes focus. Typing opens a popup of five docs pages, each with its section under its title, filtered by title or section as you type; when nothing matches, the popup says what had no result and offers a reset that clears the field and puts the keyboard back in it. The popup is portaled, so the strip stays 44 pixels tall while it's open. It's built from Autocomplete, InputGroup, Kbd, Button and Guides with Lucide icons and your theme's tokens for every colour, and it follows the theme. For documentation sites, help centres and any page that wants search one key away.

FAQ

How do I change the results and make a pick do something?

Edit PAGES at the top of the file: a label, a section shown under it and a value. Picking a result puts its title in the field, as an autocomplete does. To open the page, pass onValueChange to Autocomplete: it receives the picked value, which you can map to a route. To search a real index, replace matching(query) with your own results, fetched or local; the popup renders whatever the collection holds.

How does the filtering work?

The collection is rebuilt from the typed text on every change, comparing the title and the section without case or accents, so "publish" finds both pages in the Publishing section and "markdown" finds one. A blank field lists all five. Nothing is debounced because the list is local; for a remote index, keep the same shape and add your own delay.

How does the / key work, and does it get in the way of typing?

A key listener on the document focuses the field when "/" is pressed, unless the keyboard is already in an input, a textarea, a select or an editable element, where the key types as usual. The field declares it with aria-keyshortcuts, and the key cap is hidden from screen readers because it's a hint, not a control. On a phone the key cap is dropped, since there's no keyboard to press.

What shows when nothing matches?

The popup says "No results for" followed by the text, in a bdi so it reads right in any direction, and has an outline "Reset search" button. It clears the field, so all five pages are back, and returns focus to the input so you can type again. The strip's height is the same with the popup open, closed or empty.

How is it made accessible?

The input is a combobox with an accessible name and the popup is a listbox of options; the arrow keys move through the results, Enter picks one and Escape closes the popup. The visible product name sits beside the field and the field's own label stays "Search the docs", so the name doesn't depend on the placeholder.

How does it fit at 320 pixels?

The name shortens to "Quailcraft", the key hint is dropped and the field takes the rest, so the strip stays one line of 44 pixels. The popup is as wide as the field.

  • Pro

    A one-line shortcut hint for a docs app: key caps drawn inline that read Command K on a Mac and Ctrl K everywhere else, and an underlined link to all shortcuts.

  • Pro

    A one-line shortcut hint for a text editor, aligned to the start: three shortcuts read as a sentence, each a key cap and its verb, and a link to the full list.

  • Pro

    A dock pill for a workspace app: a toolbar of four icon buttons (New page, Search, Share, Notifications), each with a tooltip showing its name and its key.

  • Pro

    A quiet navigation strip for a product site: five section links separated by dots, with one underline that slides to the current page.

  • Pro

    A searchable FAQ for a notes app: a start-aligned header, a band with a full-width search field and a live count, and ten questions that filter as you type, open every match and mark the matched words.

  • Pro

    A 44-pixel top bar for a documentation site: a home icon and a real breadcrumb trail, whose middle crumbs fold into an ellipsis menu below the md breakpoint.