Components
Navbar
A header bar with brand, navigation links and actions, responsive with a MobileMenu.
Server-compatible (no "use client")
import.tsx
navbar-responsive.tsx
Edit on GitHubPurpose
Navbar is a site or application header: a <header> with a brand, a <nav> list of links and an
actions area. Its parts are server-compatible.
Import
import {
Navbar,
NavbarActions,
NavbarBrand,
NavbarLink,
NavbarNav,
} from "@neshel-ui/components";Usage
Preview: navbar-responsive
import {
Button,
MobileMenu,
MobileMenuContent,
MobileMenuLink,
MobileMenuNav,
MobileMenuTrigger,
Navbar,
NavbarActions,
NavbarBrand,
NavbarLink,
NavbarNav,
} from "@neshel-ui/components";
const links = [
{ href: "#home", label: "Home", active: true },
{ href: "#docs", label: "Docs" },
{ href: "#blog", label: "Blog" },
];
/** Desktop links from md; below md the MobileMenu trigger replaces them (never both). */
export default function NavbarResponsive() {
return (
<Navbar>
<NavbarBrand asChild>
<a href="#home">Acme</a>
</NavbarBrand>
<NavbarNav hideBelow="md">
{links.map((link) => (
<NavbarLink key={link.href} href={link.href} active={link.active}>
{link.label}
</NavbarLink>
))}
</NavbarNav>
<NavbarActions>
<Button size="sm">Sign in</Button>
<MobileMenu breakpoint="md">
<MobileMenuTrigger />
<MobileMenuContent>
<MobileMenuNav>
{links.map((link) => (
<MobileMenuLink key={link.href} href={link.href} active={link.active}>
{link.label}
</MobileMenuLink>
))}
</MobileMenuNav>
</MobileMenuContent>
</MobileMenu>
</NavbarActions>
</Navbar>
);
}API
| Part | Renders |
|---|---|
Navbar | <header>; sticky keeps it at the top |
NavbarBrand | div, or your link with asChild |
NavbarNav | <nav aria-label="Main"> with a <ul>; hideBelow (responsive) |
NavbarLink | <li> with an <a> (or your router link with asChild) |
NavbarActions | div for buttons and menus |
Responsive behaviour
<NavbarNav hideBelow="md"> hides the links below md; <MobileMenu breakpoint="md"> shows its
trigger only below md. Use the same breakpoint and exactly one is visible at any width — decided by
CSS, so there is no hydration flash.
Accessibility
activesetsaria-current="page"on the current link.- Give
NavbarNava distinctaria-labelif the page has several<nav>elements. --neshel-navbar-height(default3.5rem) sets the bar height.
Common mistakes
- Putting dropdown commands among the links: use a DropdownMenu
in
NavbarActions, and NavigationMenu for panels of links. - Mismatched
hideBelowandMobileMenu breakpoint, showing both or neither.