shadcn.io is not affiliated with official shadcn/ui
Editorial Category Menus Navbar Block for React
A one-bar navbar for a long-form publication whose five category triggers each open a small panel of that category's three latest pieces, with reading times as outline badges and an All stories link, and accordion groups in a sheet on phones.
Installation
Overview
An editorial navbar for React with Base UI, for a publication that wants a reader to see what's new before choosing a section. The masthead leads (an icon and the name, set by weight alone: the name bold, the word after it regular); Essays, Reviews, Interviews, Reportage and Notes each open a 320-pixel panel under their own button with that category's three latest pieces, each a title and an outline badge with its reading time, and an All stories link under a hairline. A Subscribe Shine Button ends the bar. Below the lg breakpoint a menu button opens a sheet from the top where each category is an accordion group with the same three pieces and the same link, and Subscribe sits below them. The panels and the sheet open over the page, so the block stays one bar high (56 pixels), and the bar draws no bottom border: the next block's top rule is its bottom edge. It's built from Navigation Menu, Accordion, Badge, Sheet, Guides, Shine Button and Button, with your theme's tokens for every colour. The titles and times are example copy. For magazines, newsletters and blogs whose categories are the way in.
FAQ
How do I change the categories and the pieces?
Edit CATEGORIES at the top of the file. A category has an id, a label and three pieces, each a title, a number of minutes (shown as 14 min, kept together in right-to-left pages) and an href. The panels and the sheet read the same data, so they never drift apart. Keep a title to about two lines at 320 pixels: the badge sits beside it and never shrinks. If a category has more than three pieces, add the fourth to the data and the panel grows; keep it under about 420 pixels.
Why do the panels open under their own button?
Each category is its own menu, and a small panel reads best right under what opened it, so each panel is anchored to its trigger. One panel follows the pointer from button to button, sliding and resizing as it goes; each category still shows its own three pieces.
How does it work with a keyboard and a screen reader?
The links sit in a nav landmark named Main, after the masthead (a link home). Tab reaches the masthead, the five category buttons and Subscribe. Enter or Space opens a menu, its button says whether it is expanded, and Escape closes it and puts focus back on its button. Each panel's pieces and its All stories link are a plain list of links.
Focus stays on the category button when it opens; Tab or the arrow keys move into the panel. The arrow keys also move along the bar. The menus also open on hover.
How does it work on a phone?
Below the lg breakpoint (five categories need the width) the masthead, Subscribe and a menu button stay on the bar, and nothing wraps at 320 pixels. The menu button says whether the menu is open and which panel it controls; it opens a sheet from the top whose header lines up with the bar. The categories are accordion groups, closed at first and one open at a time, each holding its three pieces with their reading times and an All stories link; Subscribe sits below, full width. Focus moves into the sheet and stays there; Escape, the close button or choosing a link closes it, and focus goes back to the menu button. A sheet taller than the screen scrolls.
Does choosing a link close the menu?
Yes, in the panels and in the sheet, so a client-side route change that keeps the navbar mounted doesn't leave a menu open over the new page.
Each link takes closeOnClick.
The sheet's open state is held in the block too (sheetOpen), and each of its links closes it. Every link points at #: point them at your pages.
Subscribe renders the link it's given with render, with nativeButton={false}.
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. To keep the bar in view while the page scrolls, add sticky top-0 z-40 bg-background/80 backdrop-blur to the header; the menus still open under it. With reduced motion the panels and the sheet appear without their fades and slides.
Related
- Pro
Flyout Panels Navbar
Mega menusA one-bar navbar for a workflow-automation tool whose three triggers each open a narrow flyout under themselves, a plain list, a described list with status badges and a promo card with a small chart, with a caret pointing at the open trigger and collapsible rows in a sheet on phones.
- Pro
SaaS Marketing Navbar
Mega menusA 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.
- Pro
Mega Menu Navbar
Mega menusA one-bar navbar for an observability platform whose Products, Resources and Company menus each open a wide panel of three link columns closed by a footer strip, with an accordion of the same links in a sheet on phones.
- Pro
Enterprise Trust Navbar
Mega menusA one-bar navbar for a workforce-management platform with Platform and Solutions menus, a hairline that splits the bar, and at its end a SOC 2 badge that opens a popover of certifications, then Try demo and a sales button.
- Pro
Master-Detail Dropdown Navbar
Mega menusA one-bar navbar for a developer cloud whose Platform and Solutions menus open a master-detail panel built as vertical tabs, a list of areas that drives the pane beside it by hover, focus or arrow keys, with a drill-down sheet on phones.
- Pro
Card Grid Mega Menu Navbar
Mega menusA one-bar navbar for a design-system suite whose Products menu opens a 3 by 2 grid of cells and whose Solutions menu opens a 2 by 3 grid of industries, cells sharing hairlines, with accordion groups in a sheet on phones.