Sidebar
An app's side navigation, in groups, that folds down to icons and slides in from the edge on phones. Same markup and props in every style: switch the style in the header to see it change.
Basic
Groups, a current page, a count and a nested list. The button folds it to icons; on a phone it slides the sidebar in. In HTML, add data-vin-sidebar and include vinui.js once.
Folded to icons
Starts folded. Each link keeps its name for screen readers and shows it as a tooltip.
Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add sidebarimport { SidebarLayout, Sidebar, SidebarHeader, SidebarContent, SidebarFooter, SidebarGroup, SidebarMenu, SidebarItem, SidebarSub, SidebarTrigger, SidebarInset } from "@/components/vin/sidebar";import SidebarLayout, { Sidebar, SidebarHeader, SidebarContent, SidebarFooter, SidebarGroup, SidebarMenu, SidebarItem, SidebarSub, SidebarTrigger, SidebarInset } from "@/components/vin/sidebar.vue";import Sidebar from "$lib/components/vin/sidebar.svelte";
import SidebarContent from "$lib/components/vin/sidebar-content.svelte";
import SidebarFooter from "$lib/components/vin/sidebar-footer.svelte";
import SidebarGroup from "$lib/components/vin/sidebar-group.svelte";
import SidebarHeader from "$lib/components/vin/sidebar-header.svelte";
import SidebarInset from "$lib/components/vin/sidebar-inset.svelte";
import SidebarItem from "$lib/components/vin/sidebar-item.svelte";
import SidebarLayout, { SIDEBAR_PHONE } from "$lib/components/vin/sidebar-layout.svelte";
import SidebarMenu from "$lib/components/vin/sidebar-menu.svelte";
import SidebarSub from "$lib/components/vin/sidebar-sub.svelte";
import SidebarTrigger from "$lib/components/vin/sidebar-trigger.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/sidebar.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
SidebarLayoutHolds the sidebar and the page beside it. Collapsed shows only the icons. | { collapsed, defaultCollapsed, onCollapsedChange } | — | .vin-sidebar-layout[data-vin-sidebar][data-state="collapsed"] |
SidebarThe navigation. On screens under 768px wide it's hidden and the trigger slides it in. | { label: string } | — | nav.vin-sidebar[popover][aria-label] |
SidebarHeader / SidebarContent / SidebarFooter | boolean | — | .vin-sidebar__header, .vin-sidebar__content (scrolls), .vin-sidebar__footer |
SidebarMenuA list of items outside a group, e.g. in the header or footer. | boolean | — | ul.vin-sidebar__menu |
SidebarGroupA heading and its list of items. | { label: string } | — | .vin-sidebar__group > .vin-sidebar__label + ul.vin-sidebar__menu[aria-labelledby] |
SidebarItemA link. active marks the current page. Give it an icon so it still shows when folded. | { href, icon, active, badge } | — | li > a.vin-sidebar__item[aria-current=page] > svg + .vin-sidebar__text + .vin-sidebar__badge? |
SidebarSubAn item that opens a nested list. | { label, icon, defaultOpen } | — | li > details.vin-sidebar__sub > summary.vin-sidebar__item + ul.vin-sidebar__submenu |
SidebarTriggerFolds the sidebar to icons, or opens it on phones. | boolean | — | button.vin-btn.vin-btn--ghost.vin-btn--icon.vin-sidebar__trigger[aria-controls][aria-expanded] |
SidebarInsetThe page next to the sidebar. | boolean | — | .vin-sidebar-inset |
--vin-sidebar-width / --vin-sidebar-min-heightOpen width (16rem) and the layout's height (100dvh). | CSS | — | — |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<SidebarLayout><Sidebar><SidebarHeader><SidebarContent><SidebarFooter><SidebarGroup><SidebarMenu><SidebarItem><SidebarSub><SidebarTrigger><SidebarInset> | .vin-sidebar-layout.vin-sidebar.vin-sidebar__header.vin-sidebar__content.vin-sidebar__footer.vin-sidebar__group.vin-sidebar__label.vin-sidebar__menu.vin-sidebar__item.vin-sidebar__text.vin-sidebar__badge.vin-sidebar__sub.vin-sidebar__submenu.vin-sidebar__trigger.vin-sidebar-inset |
Accessibility
- A nav landmark with its own name. Each group is a list named by its heading.
- The current page is marked with aria-current="page".
- The trigger is a button with aria-controls and aria-expanded, so screen readers hear whether the sidebar is open.
- Folded, the text is hidden visually but still read out, and shown as a tooltip on hover.
- On phones it opens above the page: Escape or a tap outside closes it, and focus goes back to the trigger.
Customize
Saved in this browser. Style and accent are in the header.