Web · Components
Sidebar
The app's main navigation menu: a sidebar on the left with the page content next to it.
8 exports
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Bottom navigation bar on phones: badges, bottom sheet menu, “More”
Top bar and a menu from the left on phones (mobile="sheet")
Collapsed icon strip (remembered with storageKey): name tooltip, corner badge, subpages in a menu
Import
The app's main navigation menu: a sidebar on the left with the page content next to it. Items are given with the items array; they take icons, badges, headed groups and nested sub-pages. The current page is marked automatically by the address.
- Collapsing: On desktop it collapses to an icon strip (button or ⌘B / Ctrl+B). In the strip names become tooltips, badges a dot/number at the icon corner, and sub-pages a menu opening to the right. The state is remembered with
storageKey. - Mobile:
mobile="sheet"gives a ☰ bar at the top and a menu opening from the left;mobile="bottom"gives a navigation bar with icons at the bottom (iOS/Android tab bar) and a "More" window. Windows close with the back button and by swiping, and close when a link is tapped. Bars respect notch/home bar insets; withhideOnScrollthey hide while scrolling. - Next.js: With the
@yasinsensoy/web/nextprovider, links usenext/linkand the active page is found withusePathname. In the layout write<Sidebar items={...}>{children}</Sidebar>;itemscan come from the server (icons as names), onlyonSelectis written on the client. - Performance: The desktop/mobile switch and the collapsed look are done with CSS; no screen measuring, re-rendering or hydration flicker.
- Accessibility:
<nav aria-label>,aria-current="page"on the current page,aria-expandedon sub-lists,aria-labelledbyon group headings.
Examples
SidebarItem
interfaceA page link or action inside Sidebar.
| Name | Type | Default | Description |
|---|---|---|---|
label | ReactNode | Text of the item. Also shown as a tooltip/label in the collapsed strip and the bottom bar. | |
href? | string | Address of the page. Internal addresses are rendered with the link component given to UIProvider (Next.js Link); external addresses (https://…) open in a new tab. If omitted, the item is a button (onSelect) or toggles its sub-items. | |
icon? | IconProp | Icon: name ("home") or element. Only the icon shows in the collapsed strip; only items with an icon go into the bottom navigation bar. | |
badge? | number | string | boolean | Badge on the right: a number (12; "99+" if above 99, hidden at 0), short text ("New") or true for just a dot. Shown at the icon corner in the collapsed strip and the bottom bar. | |
badgeTone? | Tone | "primary" | Badge color. |
tooltip? | TooltipProp | Tooltip shown on hover. In the collapsed strip, label is shown if omitted. See TooltipProp. | |
disabled? | boolean | Can't be selected. | |
onSelect? | (event: MouseEvent<HTMLElement>) => void | Called when clicked (e.g. to open a "New project" window). If given with href, event.preventDefault() stops navigation. Can't be passed from a server component. | |
items? | readonly SidebarItem[] | Sub-pages. In the wide view they become a collapsible list; in the collapsed strip and the bottom bar, pressing the icon opens them as a menu. | |
defaultOpen? | boolean | Whether sub-pages start open. If omitted, it starts open if one of them is active. | |
exact? | boolean | Active only when the address matches exactly. If omitted, sub-addresses also make the item active (/projects/12 → /projects). / is always compared exactly. | |
active? | boolean | Sets the active state manually; no address comparison is made. | |
bottom? | boolean | Whether it shows in the mobile bottom navigation bar. If even one item has true, only the true ones show in the bar; false removes the item from the bar. If omitted, the first top-level items with an icon go in. |
SidebarGroup
interfaceItem group with a heading ("Projects", "Settings").
| Name | Type | Description |
|---|---|---|
group | ReactNode | Heading of the group. Turns into a thin line in the collapsed strip. |
items | readonly SidebarItem[] | Items in the group. |
SidebarEntry
typeElement of the Sidebar items array: an item, a group or a "separator" line.
SidebarMobile
typeWhat replaces the sidebar on small screens?
"sheet": A thin bar at the top (☰ button andheader); the menu opens in a window sliding from the left."bottom": A navigation bar with icons at the bottom, like in apps. Items that don't fit, groups andfooterare in the "More" window in the last tab.
Threshold between the desktop and mobile view: 640, 768 or 1024 px.
SidebarClassNames
interfaceClasses that can be passed to the inner parts of Sidebar.
| Name | Type | Description |
|---|---|---|
root? | string | Root wrapping the sidebar and the page. |
aside? | string | The sidebar on desktop. |
content? | string | Column holding the page content (children). |
topBar? | string | Mobile top bar (mobile="sheet"). |
bottomBar? | string | Mobile bottom navigation bar (mobile="bottom"). |
SidebarProps
interfaceProps of the Sidebar component.
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly SidebarEntry[] | Items, groups with headings and "separator" lines. See SidebarEntry. | |
children? | ReactNode | Content of the page; rendered in the column next to the sidebar. | |
header? | ReactNode | Top area: logo, app name, team switcher. In the collapsed strip only the sidebar's width of it is visible; so put the icon/logo first. Also shown in the mobile top bar while mobile="sheet". | |
footer? | ReactNode | Bottom area: user menu, settings. Shown at the bottom of the "More" window while mobile="bottom". | |
mobile? | SidebarMobile | "sheet" | View on small screens. See SidebarMobile. |
breakpoint? | SidebarBreakpoint | "md" | Threshold for switching to the mobile view. See SidebarBreakpoint. |
responsive? | "viewport" | "container" | "viewport" | What is the threshold measured against? "viewport" is the screen width; "container" the width of the box wrapping the sidebar (split views, preview frames). While "container", position: fixed elements inside the root are positioned relative to the root. |
collapsible? | boolean | true | Whether it can collapse to an icon strip on desktop. A collapse button and shortcut are added. |
collapsed? | boolean | Whether it is collapsed in controlled use. | |
defaultCollapsed? | boolean | false | Whether it starts collapsed in uncontrolled use. |
onCollapsedChange? | (collapsed: boolean) => void | Called with the new state when collapsed or expanded. | |
storageKey? | string | The collapsed state is stored in the browser under this name and remembered on the next visit (e.g. "sidebar"). The page is drawn at the right width on first paint; no flicker. | |
shortcut? | string | false | "Mod+B" | Collapse/expand shortcut (see MenuItem.shortcut); false turns it off. Works inside text fields too, without breaking text editing. |
bottomCount? | number | 5 | Maximum number of tabs in the bottom bar while mobile="bottom" (including "More"). SidebarItem.bottom decides which items go in. |
hideOnScroll? | boolean | false | Whether the mobile bar hides while scrolling down and comes back when scrolling up. Frees more screen space on reading-heavy pages. |
currentPath? | string | Path of the current page. If omitted, it is read from the UIProvider usePathname hook (automatic in Next.js). The active item is the longest matching href. | |
mobileOpen? | boolean | Whether the mobile menu window (☰ or "More") is open in controlled use. | |
onMobileOpenChange? | (open: boolean) => void | Called when the mobile menu window opens or closes. | |
label? | string | {@link UIProvider} text ("Ana menü") | Screen reader name of the navigation region. |
width? | string | "16rem" | Width of the sidebar (CSS length). |
className? | string | Classes added to the root. | |
classNames? | SidebarClassNames | Classes added to the inner parts. | |
style? | CSSProperties | Styles added to the root. | |
effect? | EffectProp | Effect or effects of the item rows (also plays on the active row) (e.g. "ripple", ["border", "glow"]). If omitted, UIProvider appearance.defaults.sidebar.effect. See BuiltinEffect. |