Skip to content

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:

Terminal
npx @vinish/ui add sidebar
React
import { SidebarLayout, Sidebar, SidebarHeader, SidebarContent, SidebarFooter, SidebarGroup, SidebarMenu, SidebarItem, SidebarSub, SidebarTrigger, SidebarInset } from "@/components/vin/sidebar";
Vue
import SidebarLayout, { Sidebar, SidebarHeader, SidebarContent, SidebarFooter, SidebarGroup, SidebarMenu, SidebarItem, SidebarSub, SidebarTrigger, SidebarInset } from "@/components/vin/sidebar.vue";
Svelte
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.

PropValuesDefaultIn HTML
SidebarLayout
Holds the sidebar and the page beside it. Collapsed shows only the icons.
{ collapsed, defaultCollapsed, onCollapsedChange }—.vin-sidebar-layout[data-vin-sidebar][data-state="collapsed"]
Sidebar
The 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 / SidebarFooterboolean—.vin-sidebar__header, .vin-sidebar__content (scrolls), .vin-sidebar__footer
SidebarMenu
A list of items outside a group, e.g. in the header or footer.
boolean—ul.vin-sidebar__menu
SidebarGroup
A heading and its list of items.
{ label: string }—.vin-sidebar__group > .vin-sidebar__label + ul.vin-sidebar__menu[aria-labelledby]
SidebarItem
A 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?
SidebarSub
An item that opens a nested list.
{ label, icon, defaultOpen }—li > details.vin-sidebar__sub > summary.vin-sidebar__item + ul.vin-sidebar__submenu
SidebarTrigger
Folds 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]
SidebarInset
The page next to the sidebar.
boolean—.vin-sidebar-inset
--vin-sidebar-width / --vin-sidebar-min-height
Open width (16rem) and the layout's height (100dvh).
CSS——

Parts

React, Vue, SvelteHTML 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.