Display & Navigation · Top Navstable
Top Nav
The application header with brand, primary links, a search slot and account actions, collapsing to brand and a menu button on small screens.
Preview
#previewSwitch the active link, link state, search and menu button. Links and search hide under the md breakpoint. Show code opens the React and CSS below.
RC
overview · default · yes · yes
top-nav-example.tsx
import { TopNav, TopNavAvatar } from "@blade-ai/weft/components/top-nav";
export function AppHeader({ pathname, openDrawer }: Props) {
return (
<TopNav
brandName="Blade"
links={[
{ label: "Overview", href: "/", isActive: pathname === "/" },
{ label: "Payments", href: "/payments", isActive: pathname === "/payments" },
{ label: "Customers", href: "/customers", isActive: pathname === "/customers" },
]}
search={<SearchField />}
onMenuClick={openDrawer}
actions={<TopNavAvatar initials="RC" accessibilityLabel="Romeet Chatterjee" />}
/>
);
}Props
#propsTopNav, TopNavItem and TopNavAvatar.
TopNav
Prop
Type
Default
Description
brandName
string
—
Brand name next to the mark. Required.
brandMark
ReactNode
—
Brand mark node. Defaults to the first letter of brandName on a primary square.
brandHref
string
"/"
Where the brand links to.
links
TopNavLink[]
[]
Primary destinations. Hidden under md; supply onMenuClick to open them elsewhere.
search
ReactNode
—
Right side, before actions: usually a search field. Hidden under md.
actions
ReactNode
—
Right side: icon buttons and the account avatar or Menu trigger.
onMenuClick
() => void
—
Shows the mobile menu button (under md) and fires on press.
menuLabel
string
"Open menu"
Accessible name of the mobile menu button.
accessibilityLabel
string
"Main"
Accessible name of the nav landmark.
className
string
—
Extra classes on the header.
TopNavItem / TopNavLink
Prop
Type
Default
Description
label
string
—
Link text. Required.
href
string
—
Destination. Required.
isActive
boolean
false
The current page: primary underline, aria-current="page".
data-state
"hover" | "focus"
—
Docs and testing hook: forces a visual state.
TopNavAvatar
Prop
Type
Default
Description
initials
string
—
Two letters in a 24px chip. Required.
accessibilityLabel
string
—
Names the avatar. Without it the avatar is hidden from assistive tech.
className
string
—
Extra classes.
Usage
#usageShort rules for choosing and writing top navigation.
Do
Keep to three to six top-level links.
Mark the current page with isActive.
Provide onMenuClick so small screens can reach the links.
Put account and utility actions on the right.
Don't
Do not put long labels or two-line links in the bar.
Do not hide the only route to a page on small screens.
Do not use it for in-page switching; use Tabs.
Do not nest a second row of navigation inside it.
Accessibility
#accessibilityA header with a labelled nav landmark. The current page carries aria-current.
Keyboard
Key
Action
Tab
Moves through brand, links, search and actions.
Enter
Follows the focused link or activates the focused button.
ARIA
Element
Role / attribute
When
Header
<header>
Always. Banner landmark.
Links
<nav> · aria-label
When links are set. Label from accessibilityLabel.
Active link
aria-current="page"
On the link with isActive.
Menu button
aria-label
When onMenuClick is set. Visible under md only.
Avatar
role="img" · aria-label
Only when accessibilityLabel is set; otherwise aria-hidden.