Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Search Overlay Navbar Block for React

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.

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-overlay navbar for React with Base UI, the bar a research site keeps above its pages. For Briefharbor, a legal-research database, the wordmark leads, four links follow (Cases, Statutes, Journals, Guides) and a search button that looks like a field, with its "/" key cap, sits beside a Start trial Shine Button. The button, or "/", opens a panel from the top that takes the bar's place: a large search field, then, with the field empty, Recent searches (each with its own remove button, and a Clear all) and Popular topics as tags; as you type, the twelve pages that match (cases, statutes, journals and guides, each with its kind and topic) with the matching letters marked, a count, or an empty state with a way back. Pressing Enter keeps a search among the recents, and choosing a result closes the panel and keeps it too. Escape closes the panel and returns the keyboard to the button. The panel is at most 288 pixels of content under a 64 pixel header, and the bar behind it never changes height. On a phone the button shrinks to an icon, and a second sheet carries the links. It's built from Sheet, Input Group, Search Highlight Text, Badge, Kbd, Shine Button, Button and Guides with Lucide icons and your theme's tokens for every colour. For research, documentation and archive sites where search is the main way in.

FAQ

How do I change the pages and the topics?

Edit RESULTS at the top of the file (a title, a kind and a topic each), POPULAR for the tags and RECENT_AT_START for the searches the panel opens with. The panel filters RESULTS by title, kind and topic, ignoring case and accents. To search a real index, replace matching(query) with your own results; the list renders whatever it returns. The links in the bar and the phone sheet come from PAGES.

How do the recent searches work?

They are kept in the block's state, newest first, with no repeats and at most five. Pressing Enter in the field keeps what you typed, and so does choosing a result. Each row has a button that runs the search again and a separate button, named "Remove" followed by the search, that drops it; Clear all empties the list, which then says how to fill it. After each of these the keyboard goes back to the field. Nothing is saved between visits: store the list yourself if you want it to last.

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

The search button says whether the panel is open and, while it is, which panel it controls. Opening it moves the keyboard to the large field, the first thing in the panel; Tab moves through the field, its clear button, the close button, the rows and the tags without leaving the panel, and the Down arrow in the field jumps to the first result. Escape closes the panel and returns the keyboard to the button. The field sits in a search landmark inside a dialog named "Search Briefharbor", the count is announced in a polite status line, and the key cap is hidden from screen readers because it only hints. The "/" key opens the panel from anywhere that isn't a text field.

What are the marked letters, and what if nothing matches?

Each result's title is drawn with Search Highlight Text, which marks the typed letters on a light tint of the text colour, so the words keep their contrast in every theme. When nothing matches, the panel says what had no result, in a bdi so it reads right in any direction, and offers a Clear search button that empties the field and returns the keyboard to it; the popular topics stay in view.

How does it work on a phone?

Below the md breakpoint the search button is an icon (its accessible name is still "Search cases and statutes"), beside a menu button, and Start trial moves into the menu below the sm breakpoint. The panel is the same sheet from the top; the recents and results come first and the popular topics follow, and a sheet taller than the screen scrolls. The menu button opens a separate sheet with the four links and Start trial, its header lined up with the bar. Both sheets trap focus, close on Escape and return focus to the button that opened them.

How does it sit on the page, and can it stick to the top?

The navbar is the page's first block: its + marks and rails line up with every block under it, its top rule falls on the window's top edge, and it draws no bottom border, because the next block's top rule is its bottom edge. The panel opens over the page, so nothing below moves. To keep the bar in view while the page scrolls, add sticky top-0 z-40 bg-background/80 backdrop-blur to the header. Every link points at #: point them at your pages. Start trial renders the link it's given with render, with nativeButton={false}.

  • 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 navbar for a recipe library whose search button grows a field inside the bar, pushing the links aside on shared grid tracks, with a clear button, an Esc hint and a live count of matching recipes.

  • 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 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 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 one-bar marketing navbar for a product roadmap tool: a wordmark, a Product menu of four areas with icons and one-line descriptions, plain links with the current page marked, Sign in and a Shine Button, and a sheet with the same links on phones.