A responsive navigation header positioned on top side of the page that has affordances for branding, links, actions, etc.
import {
Navbar,
NavbarBrand,
NavbarContent,
NavbarItem,
NavbarMenu,
NavbarMenuItem,
NavbarMenuToggle,
} from "@opengovsg/oui"<Navbar>
<NavbarBrand>
<p className="font-bold">OUI</p>
</NavbarBrand>
<NavbarContent justify="center">
<NavbarItem>
<Link href="#">Features</Link>
</NavbarItem>
<NavbarItem isActive>
<Link href="#">Customers</Link>
</NavbarItem>
</NavbarContent>
<NavbarContent justify="end">
<NavbarItem>
<Link href="#">Login</Link>
</NavbarItem>
</NavbarContent>
</Navbar>OUI exports 7 navbar-related components:
You can use the NavbarMenuToggle and NavbarMenu components to display a togglable menu. This is commonly used for mobile navigation.
You can use the position prop to make the navbar static positioned (the default behavior is sticky).
You can use the shouldShowOnScrollUp prop to make the navbar show when the user scrolls up. This is useful for providing quick access to navigation while maximizing content visibility.
Note: This prop only takes effect when
positionis set tostatic.
You can use the isMenuOpen and onMenuOpenChange props to control the navbar menu state programmatically.
By default, the navbar has a bottom border. You can use the hasBorder prop to control its visibility.
Set hasBorder={false} to remove the bottom border from the navbar.
When the NavbarItem has isActive set to true, it will have a data-active attribute. You can use this attribute to customize the active state styling.
brand, content and toggle.NavbarBrand component.NavbarContent component.NavbarItem component.NavbarMenuToggle component.NavbarMenuToggle icon.NavbarMenu component.NavbarMenuItem component.Navbar has the following attributes on the base element:
shouldShowOnScrollUp prop is true.NavbarContent:
start, center, or end).NavbarItem has the following attributes on the base element:
isActive prop is true.NavbarMenuToggle has the following attributes on the base element:
NavbarMenuItem has the following attributes on the base element:
isActive prop is true.| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | The content of the navbar |
| height | string | number | "4rem" | The height of the navbar |
| position | "static" | "sticky" | "sticky" | The CSS position of the navbar |
| hasBorder | boolean | true | Whether to show a bottom border |
| isMenuOpen | boolean | false | Whether the menu is open (controlled) |
| isMenuDefaultOpen | boolean | false | Whether the menu should be open by default |
| shouldBlockScroll | boolean | true | Whether to block scroll when menu is open |
| shouldShowOnScrollUp | boolean | false | Whether to show navbar when scrolling up (only works with position="static") |
| disableScrollHandler | boolean | false | Whether to disable the scroll event handler |
| classNames | Record<Slot, string> | - | Classes to apply to each slot |
| Prop | Type | Description |
|---|---|---|
| onMenuOpenChange | (isOpen: boolean) => void | Handler called when the menu open state changes |
| onScrollPositionChange | (scrollPosition: number) => void | Handler called when scroll position changes |
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | The content items |
| justify | "start" | "center" | "end" | "start" | The justify content alignment |
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | The content of the item |
| isActive | boolean | false | Whether the item is active |
| Prop | Type | Default | Description |
|---|---|---|---|
| icon | ReactNode | ((isOpen: boolean) => ReactNode) | - | Custom icon to display |
| size | "xs" | "sm" | "md" | "lg" | "sm" | The size of the toggle button |
| classNames | Record<"toggle" | "toggleIcon", string> | - | Classes for toggle slots |
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | The menu items |
| portalContainer | Element | Below navbar | The container for the menu portal |
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | The content of the menu item |
| isActive | boolean | false | Whether the menu item is active |
| className | string | ((props: { isActive: boolean }) => string) | - | Class name or render function |