OverviewInstallationMigrating to 1.0Themes and layersKanok designCustomizingIconsForms and validationFrameworksUsing with AIButtonText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderModalSide panelTearsheetNotificationToastTooltipDefinition tooltipPopoverToggletipMenuData tableStructured listPaginationContained listTree viewTabsBreadcrumbLinkPagination navContent switcherAccordionProgress indicatorUI shellTagTileCardProduct cardCode snippetCopy buttonUser avatarTruncated textListLoadingInline loadingProgress barSkeletonBadge indicatorStatus indicatorGridHeadingLayerAction setPage headerBig numberEdit in placeIntroductionText inputText areaNumber inputSearchSelectDropdownComboboxMulti-selectCheckboxRadio buttonToggleDate pickerTime pickerSliderFile uploaderTabsPagination navContent switcherTooltipDefinition tooltipPopoverMenuAccordionProgress indicatorUI shellModalSide panelTearsheetNotificationToastData tableStructured listPaginationTree viewCode snippetCopy buttonTruncated textLoadingTagCardProduct cardEdit in place
UI shell
The UI shell is the frame of an application: a 48px header fixed at the top, a side navigation on the left and the content area beside them. The header holds the product name, the main menu bar and icon buttons for global actions; the side nav holds the sections of the product.
This site is built with these elements: the header above this page and the side nav on its left are the live example. The examples below run in framed boxes of their own; Examples on this page says why.
The …Icon components on this page are Carbon's icons from @carbon/icons-react, imported with an Icon suffix (see Icons). The header shows them at 20px and the side nav at 16px; in the React tabs they pass slot on to their <svg>.
Installation
npmshadcn · Web componentshadcn · React + TailwindManualnpminstall@purpurabog/uinpxshadcn@4add@kanok-ui/shellnpxshadcn@4add@kanok-ui/tw-header@kanok-ui/tw-side-nav# Web component# 1. Install the dependenciesnpminstalllit@^3.3.0# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/shell.json# to its target:# components/ui/primitives/shell/content.ts# components/ui/primitives/shell/header-global-action.ts# components/ui/primitives/shell/header-global-bar.ts# components/ui/primitives/shell/header-mega-group.ts# components/ui/primitives/shell/header-mega-item.ts# components/ui/primitives/shell/header-mega-menu.ts# components/ui/primitives/shell/header-menu-button.ts# components/ui/primitives/shell/header-menu-item.ts# components/ui/primitives/shell/header-menu.ts# components/ui/primitives/shell/header-name.ts# components/ui/primitives/shell/header-nav.ts# components/ui/primitives/shell/header-panel.ts# components/ui/primitives/shell/header.ts# components/ui/primitives/shell/shell-shared.ts# components/ui/primitives/shell/shell.ts# components/ui/primitives/shell/side-nav-divider.ts# components/ui/primitives/shell/side-nav-items.ts# components/ui/primitives/shell/side-nav-link.ts# components/ui/primitives/shell/side-nav-menu-item.ts# components/ui/primitives/shell/side-nav-menu.ts# components/ui/primitives/shell/side-nav.ts# components/ui/primitives/shell/skip-to-content.ts# components/ui/primitives/shell/switcher-item.ts# components/ui/primitives/shell/switcher.ts# 3. Do the same for the items it needs (registry/<name>.json):# core-mega-menu, core-overlay, core-popup, shared-element, shared-events, shared-field, shared-localize, shared-navigate, shared-slots, tooltip, tokens# React + Tailwind# 1. Install the dependenciesnpminstall@purpurabog/ui@^2.3.0# 2. Copy each file's "content" from# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-header.json# https://cdn.jsdelivr.net/npm/@purpurabog/ui@2.3.0/registry/tw-side-nav.json# to its target:# components/ui/react-tw/header.tsx# components/ui/react-tw/side-nav.tsx# 3. Do the same for the items it needs (registry/<name>.json):# core-overlay, tw-i18n, tw-refs, tw-theme, tw-tooltip, tw-utils
npm gives you every component from the package. shadcn copies the source into your app instead: a copy pinned to this version that you can change. The shadcn commands need the @kanok-ui registry in your components.json once, see Installation.
Use it
Put the header, the side nav and the content straight into <body>, in this order. A page has one shell.
The web components wire themselves: the hamburger opens and closes the side nav in the same document with no code, and <ui-content> moves aside for the side nav. In React + Tailwind, hold the side nav's state yourself, as above.
Examples on this page
The header and the side nav are position: fixed: they stick to the window, and the hamburger and the content area look for the side nav in their document. This page already has a shell, so each live example below sits in a box whose transform keeps the fixed parts inside it, and runs in the box's own shadow root (a "micro app"), so the page's hamburger and the example's side nav don't drive each other. The demo script also cancels the links' ui-navigate, so a click in an example doesn't leave this page.
None of that is needed in your app. The React tabs show the code as you would write it.
The header's menu bar shows from Carbon's lg breakpoint, 1056px wide; below it the hamburger appears and the side nav slides over the page. The breakpoint is the window's width, not the box's: make the window narrower to see the small-screen layout.
Menu bar
<ui-header-nav> is the main menu bar after the product name. It holds <ui-header-menu-item> links and <ui-header-menu> dropdowns of more links. current marks the page with a 3px bar. A closed menu shows the bar when one of its items is current; current on the menu shows it always.
prefix on <ui-header-name> is the part of the name in regular weight (Carbon's "IBM"); the rest is semibold.
ContractsRequestsTemplatesMonthlyYearlyAudit log
HTMLReactReact + Tailwind<divid="ui-shell-menus"style="transform: translateZ(0); position: relative; height: 240px; overflow: hidden; border: 1px solid var(--ui-hairline)">
<template>
<ui-headerlabel="Metro Contracts">
<ui-header-namehref="#home"prefix="Metro">Contracts</ui-header-name>
<ui-header-navlabel="Metro Contracts">
<ui-header-menu-itemhref="#requests">Requests</ui-header-menu-item>
<ui-header-menu-itemhref="#templates">Templates</ui-header-menu-item>
<ui-header-menulabel="Reports">
<ui-header-menu-itemhref="#monthly"current>Monthly</ui-header-menu-item>
<ui-header-menu-itemhref="#yearly">Yearly</ui-header-menu-item>
<ui-header-menu-itemhref="#audit">Audit log</ui-header-menu-item>
</ui-header-menu>
</ui-header-nav>
</ui-header>
</template>
</div>
<scripttype="module">
// docs only: the example gets a shadow root of its own (this page has its own shell)const box = document.getElementById('ui-shell-menus');
const shell = box.attachShadow({ mode:'open' });
shell.append(document.importNode(box.querySelector('template').content, true));
shell.addEventListener('ui-navigate', (event) => {
event.preventDefault(); // stay on this page
event.stopPropagation();
});
</script><UiHeaderlabel="Metro Contracts">
<UiHeaderNamehref="/"prefix="Metro">Contracts</UiHeaderName>
<UiHeaderNavlabel="Metro Contracts">
<UiHeaderMenuItemhref="/requests">Requests</UiHeaderMenuItem>
<UiHeaderMenuItemhref="/templates">Templates</UiHeaderMenuItem>
<UiHeaderMenulabel="Reports">
<UiHeaderMenuItemhref="/reports/monthly"current>Monthly</UiHeaderMenuItem>
<UiHeaderMenuItemhref="/reports/yearly">Yearly</UiHeaderMenuItem>
<UiHeaderMenuItemhref="/reports/audit">Audit log</UiHeaderMenuItem>
</UiHeaderMenu>
</UiHeaderNav>
</UiHeader><Headeraria-label="Metro Contracts">
<HeaderNamehref="/"prefix="Metro">Contracts</HeaderName>
<HeaderNavigationaria-label="Metro Contracts">
<HeaderMenuItemhref="/requests">Requests</HeaderMenuItem>
<HeaderMenuItemhref="/templates">Templates</HeaderMenuItem>
<HeaderMenulabel="Reports">
<HeaderMenuItemhref="/reports/monthly"current>Monthly</HeaderMenuItem>
<HeaderMenuItemhref="/reports/yearly">Yearly</HeaderMenuItem>
<HeaderMenuItemhref="/reports/audit">Audit log</HeaderMenuItem>
</HeaderMenu>
</HeaderNavigation>
</Header>
A header menu is a disclosure, not an ARIA menu: its links stay links. Click, Enter or Space opens it; Esc or a click outside closes it and focus goes back to its title. Following one of its links closes it too.
Mega menu
A <ui-header-mega-menu> opens a panel as wide as the header under it, with <ui-header-mega-group> columns of <ui-header-mega-item> links (a mega menu, as on Vercel's site). Put it in <ui-header-nav> next to plain links and <ui-header-menu>s. A group has a small heading; an item is a title, and may have an icon slot and a one-line description (the Products menu below). current on an item marks the page, and the closed menu shows the 3px bar.
The panel opens in the browser's top layer, so a host app's own fixed bars can't cover it whatever their z-index: right for an app that sits inside another product's shell.
With a mouse, resting on an entry opens its panel after 150ms, and while one is open, moving along the bar switches at once. Leaving the entry and its panel closes a panel the pointer opened after 300ms (enough for a diagonal path down to a link). A click holds it open; a finger opens it with a tap. Click, Enter or Space opens and closes it, ↓ opens it and moves to the first link, and Esc, a click outside, Tab out of it or following a link closes it. One panel is open at a time.
Kanok draws the panel white over a hairline with a soft shadow, the links at 20px (as Vercel) and the group headings at 14px. The --ui-mega-* settings change these for any design.
Global actions
<ui-header-global-bar> holds the icon buttons at the end of the header. Each <ui-header-global-action> is named by label, which also shows as its tooltip; tooltip-placement="bottom-end" keeps the tooltip of the last button inside the window. active gives a button the pressed look (aria-pressed), for an action that turns something on or off.
<ui-header-panel> is a 256px panel that slides in under the header at the end side, for notifications, a profile or settings. Give it an id and put that id in the panel attribute of a global action: a click on the action opens and closes the panel, and the action shows as pressed while it is open (aria-expanded). Esc, a click outside or focus leaving the panel closes it. label names the panel as a region.
Contracts
Somchai signed the lease for unit 4B.
The cleaning contract ends in 30 days.
All notifications
HTMLReactReact + Tailwind<divid="ui-shell-panel"style="transform: translateZ(0); position: relative; height: 320px; overflow: hidden; border: 1px solid var(--ui-hairline)">
<template>
<ui-headerlabel="Metro Contracts">
<ui-header-namehref="#home"prefix="Metro">Contracts</ui-header-name>
<ui-header-global-bar>
<ui-header-global-actionlabel="Notifications"panel="ui-shell-panel-notes"tooltip-placement="bottom-end">
<svgviewBox="0 0 20 20"aria-hidden="true"><pathd="M17 14.3V13l-1.5-1.5V8a5.5 5.5 0 0 0-4.6-5.4V1.4H9.1v1.2A5.5 5.5 0 0 0 4.5 8v3.5L3 13v1.3h4.4a2.6 2.6 0 0 0 5.2 0ZM10 15.9a1.3 1.3 0 0 1-1.3-1.3h2.6a1.3 1.3 0 0 1-1.3 1.3Z" /></svg>
</ui-header-global-action>
</ui-header-global-bar>
<ui-header-panelid="ui-shell-panel-notes"label="Notifications">
<divstyle="display: grid; gap: 16px; padding: 16px; font: var(--ui-font-body-sm)">
<pstyle="margin: 0">Somchai signed the lease for unit 4B.</p>
<pstyle="margin: 0">The cleaning contract ends in 30 days.</p>
<ui-linkhref="#notifications">All notifications</ui-link>
</div>
</ui-header-panel>
</ui-header>
</template>
</div>
<scripttype="module">
// docs only: the example gets a shadow root of its own (this page has its own shell)const box = document.getElementById('ui-shell-panel');
const shell = box.attachShadow({ mode:'open' });
shell.append(document.importNode(box.querySelector('template').content, true));
shell.addEventListener('ui-navigate', (event) => {
event.preventDefault(); // stay on this page
event.stopPropagation();
});
</script>import { Notification as NotificationIcon } from'@carbon/icons-react';
<UiHeaderGlobalBar>
<UiHeaderGlobalActionlabel="Notifications"panel="notifications"tooltipPlacement="bottom-end"><NotificationIcon /></UiHeaderGlobalAction>
</UiHeaderGlobalBar>
<UiHeaderPanelid="notifications"label="Notifications">
<p>Somchai signed the lease for unit 4B.</p>
<p>The cleaning contract ends in 30 days.</p>
<UiLinkhref="/notifications">All notifications</UiLink>
</UiHeaderPanel>import { Notification as NotificationIcon } from'@carbon/icons-react';
const [open, setOpen] =useState(false);
<HeaderGlobalBar>
<HeaderGlobalActionlabel="Notifications"tooltipPlacement="bottom-end"expanded={open} aria-controls="notifications"onClick={() =>setOpen(!open)}>
<NotificationIcon />
</HeaderGlobalAction>
</HeaderGlobalBar>
<HeaderPanelid="notifications"aria-label="Notifications"expanded={open} onClose={() =>setOpen(false)}>
<p>Somchai signed the lease for unit 4B.</p>
<p>The cleaning contract ends in 30 days.</p>
<Linkhref="/notifications">All notifications</Link>
</HeaderPanel>
In React + Tailwind the panel is controlled: expanded on the action makes it a disclosure, and onClose tells you why the panel asks to close ('escape', 'blur' or 'outside'). A click on the action whose aria-controls is the panel's id doesn't count as outside.
App switcher
<ui-switcher> in a header panel lists the other applications. <ui-switcher-item> is a link; selected marks the application you are in (aria-current="page"). An <hr> between items draws a divider. Links to other sites take target and rel as on <a>.
<ui-side-nav> holds one <ui-side-nav-items> list of:
<ui-side-nav-link>: a link; current marks the page with a 3px bar.
<ui-side-nav-menu label>: a group that opens and closes, holding <ui-side-nav-menu-item> links. expanded opens it on load. Closed, it shows the bar when one of its items is current.
<ui-side-nav-divider>: a line between groups.
A 16px icon in the icon slot of a link or menu goes before the text; the menu's items then indent past it. large makes a row 48px tall.
By default (no mode attribute) the side nav is open beside the content from 1056px. Below that it is closed: the hamburger opens it over the page with a dark overlay, and a click on the overlay, Esc or focus leaving it closes it again.
Rail
rail makes the side nav a 48px strip of icons. It opens to 256px over the content while the pointer is on it or focus is inside, and the content keeps its 48px offset. Give every link and menu an icon.
HTMLReactReact + Tailwind<divid="ui-shell-rail"style="transform: translateZ(0); position: relative; height: 360px; overflow: hidden; border: 1px solid var(--ui-hairline)">
<template>
<ui-headerlabel="Metro Contracts">
<ui-header-menu-button></ui-header-menu-button>
<ui-header-namehref="#home"prefix="Metro">Contracts</ui-header-name>
</ui-header>
<ui-side-navraillabel="Sections">
<ui-side-nav-items>
<ui-side-nav-linkhref="#dashboard"current>
<svgslot="icon"viewBox="0 0 16 16"aria-hidden="true"><pathd="M2 2h5v5H2zm7 0h5v5H9zM2 9h5v5H2zm7 0h5v5H9z" /></svg>
Dashboard
</ui-side-nav-link>
<ui-side-nav-menulabel="Requests">
<svgslot="icon"viewBox="0 0 16 16"aria-hidden="true"><pathd="M13 3.6 10.4 1H3v14h10zM10 2.4 11.6 4H10zM4 14V2h5v3h3v9z" /></svg>
<ui-side-nav-menu-itemhref="#open">Open</ui-side-nav-menu-item>
<ui-side-nav-menu-itemhref="#signing">Awaiting signature</ui-side-nav-menu-item>
</ui-side-nav-menu>
<ui-side-nav-linkhref="#settings">
<svgslot="icon"viewBox="0 0 16 16"aria-hidden="true"><pathd="M13.5 8.4a5.4 5.4 0 0 0 0-.8l1.4-1.1-1.3-2.3-1.7.6a5 5 0 0 0-.7-.4L10.9 2.6H8.3L8 4.4l-.7.4-1.7-.6-1.3 2.3 1.4 1.1a5.4 5.4 0 0 0 0 .8L4.3 9.5l1.3 2.3 1.7-.6.7.4.3 1.8h2.6l.3-1.8.7-.4 1.7.6 1.3-2.3zM9.6 10a2 2 0 1 1 0-4 2 2 0 0 1 0 4Z" /></svg>
Settings
</ui-side-nav-link>
</ui-side-nav-items>
</ui-side-nav>
<ui-contentid="ui-shell-rail-main">
<pstyle="margin: 0; font: var(--ui-font-body)">Point at the strip on the left, or Tab into it.</p>
</ui-content>
</template>
</div>
<scripttype="module">
// docs only: the example gets a shadow root of its own (this page has its own shell)const box = document.getElementById('ui-shell-rail');
const shell = box.attachShadow({ mode:'open' });
shell.append(document.importNode(box.querySelector('template').content, true));
shell.addEventListener('ui-navigate', (event) => {
event.preventDefault(); // stay on this page
event.stopPropagation();
});
</script>import { Dashboard as DashboardIcon, Document as DocumentIcon, Settings as SettingsIcon } from'@carbon/icons-react';
<UiSideNavraillabel="Sections">
<UiSideNavItems>
<UiSideNavLinkhref="/"current><DashboardIconslot="icon" />Dashboard</UiSideNavLink>
<UiSideNavMenulabel="Requests">
<DocumentIconslot="icon" />
<UiSideNavMenuItemhref="/requests/open">Open</UiSideNavMenuItem>
<UiSideNavMenuItemhref="/requests/signing">Awaiting signature</UiSideNavMenuItem>
</UiSideNavMenu>
<UiSideNavLinkhref="/settings"><SettingsIconslot="icon" />Settings</UiSideNavLink>
</UiSideNavItems>
</UiSideNav>import { Dashboard as DashboardIcon, Document as DocumentIcon, Settings as SettingsIcon } from'@carbon/icons-react';
<SideNavrailaria-label="Sections"expanded={navOpen} onToggle={setNavOpen}>
<SideNavItems>
<SideNavLinkhref="/"icon={<DashboardIcon />} current>Dashboard</SideNavLink>
<SideNavMenulabel="Requests"icon={<DocumentIcon />}>
<SideNavMenuItemhref="/requests/open">Open</SideNavMenuItem>
<SideNavMenuItemhref="/requests/signing">Awaiting signature</SideNavMenuItem>
</SideNavMenu>
<SideNavLinkhref="/settings"icon={<SettingsIcon />}>Settings</SideNavLink>
</SideNavItems>
</SideNav>
Fixed
fixed together with expanded keeps the side nav open at 256px at every width, and the content moves aside for it. There is no overlay. Use it for tools people work in all day, where the sections must always be in view.
ContractsDashboardRequestsTemplates
The content starts 256px in, at every width.
HTMLReactReact + Tailwind<divid="ui-shell-fixed"style="transform: translateZ(0); position: relative; height: 320px; overflow: hidden; border: 1px solid var(--ui-hairline)">
<template>
<ui-headerlabel="Metro Contracts">
<ui-header-namehref="#home"prefix="Metro">Contracts</ui-header-name>
</ui-header>
<ui-side-navfixedexpandedlabel="Sections">
<ui-side-nav-items>
<ui-side-nav-linkhref="#dashboard"current>Dashboard</ui-side-nav-link>
<ui-side-nav-linkhref="#requests">Requests</ui-side-nav-link>
<ui-side-nav-linkhref="#templates">Templates</ui-side-nav-link>
</ui-side-nav-items>
</ui-side-nav>
<ui-contentid="ui-shell-fixed-main">
<pstyle="margin: 0; font: var(--ui-font-body)">The content starts 256px in, at every width.</p>
</ui-content>
</template>
</div>
<scripttype="module">
// docs only: the example gets a shadow root of its own (this page has its own shell)const box = document.getElementById('ui-shell-fixed');
const shell = box.attachShadow({ mode:'open' });
shell.append(document.importNode(box.querySelector('template').content, true));
shell.addEventListener('ui-navigate', (event) => {
event.preventDefault(); // stay on this page
event.stopPropagation();
});
</script><UiSideNavfixedexpandedlabel="Sections">
<UiSideNavItems>
<UiSideNavLinkhref="/"current>Dashboard</UiSideNavLink>
<UiSideNavLinkhref="/requests">Requests</UiSideNavLink>
<UiSideNavLinkhref="/templates">Templates</UiSideNavLink>
</UiSideNavItems>
</UiSideNav>
<UiContent>…</UiContent><SideNavfixedexpandedaria-label="Sections">
<SideNavItems>
<SideNavLinkhref="/"current>Dashboard</SideNavLink>
<SideNavLinkhref="/requests">Requests</SideNavLink>
<SideNavLinkhref="/templates">Templates</SideNavLink>
</SideNavItems>
</SideNav>
<Content>…</Content>
fixed without expanded slides the nav out of view while the content keeps its 256px offset, so set both.
Collapsible
collapsible (Carbon's isPersistent={false}) keeps the side nav closed at every width, and the hamburger shows on large screens too. The nav opens over the content, which doesn't move; Esc or focus leaving the nav closes it. Use it when the content needs the whole width.
ContractsDashboardRequestsTemplates
Open the menu with the hamburger at the top left.
HTMLReactReact + Tailwind<divid="ui-shell-collapsible"style="transform: translateZ(0); position: relative; height: 320px; overflow: hidden; border: 1px solid var(--ui-hairline)">
<template>
<ui-headerlabel="Metro Contracts">
<ui-header-menu-button></ui-header-menu-button>
<ui-header-namehref="#home"prefix="Metro">Contracts</ui-header-name>
</ui-header>
<ui-side-navcollapsiblelabel="Sections">
<ui-side-nav-items>
<ui-side-nav-linkhref="#dashboard"current>Dashboard</ui-side-nav-link>
<ui-side-nav-linkhref="#requests">Requests</ui-side-nav-link>
<ui-side-nav-linkhref="#templates">Templates</ui-side-nav-link>
</ui-side-nav-items>
</ui-side-nav>
<ui-contentid="ui-shell-collapsible-main">
<pstyle="margin: 0; font: var(--ui-font-body)">Open the menu with the hamburger at the top left.</p>
</ui-content>
</template>
</div>
<scripttype="module">
// docs only: the example gets a shadow root of its own (this page has its own shell)const box = document.getElementById('ui-shell-collapsible');
const shell = box.attachShadow({ mode:'open' });
shell.append(document.importNode(box.querySelector('template').content, true));
shell.addEventListener('ui-navigate', (event) => {
event.preventDefault(); // stay on this page
event.stopPropagation();
});
</script><UiHeaderlabel="Metro Contracts">
<UiHeaderMenuButton />
<UiHeaderNamehref="/"prefix="Metro">Contracts</UiHeaderName>
</UiHeader>
<UiSideNavcollapsiblelabel="Sections">…</UiSideNav>
<UiContent>…</UiContent>const [navOpen, setNavOpen] =useState(false);
<Headeraria-label="Metro Contracts">
<HeaderMenuButtoncollapsibleactive={navOpen} onToggle={setNavOpen} />
<HeaderNamehref="/"prefix="Metro">Contracts</HeaderName>
</Header>
<SideNavcollapsiblearia-label="Sections"expanded={navOpen} onToggle={setNavOpen}>…</SideNav>
<Content>…</Content>
The web component's hamburger finds the collapsible side nav and stays visible by itself. In React + Tailwind, set collapsible on HeaderMenuButton too.
Header links on small screens
Below 1056px the header's menu bar is hidden. Put a second <ui-header-nav> with the same links first inside <ui-side-nav>: it shows there as a column on small screens only (Carbon's HeaderSideNavItems), and it doesn't make a second navigation landmark. Make the window narrower than 1056px and open the hamburger to see it.
When the header has no side nav (an app inside another product, which keeps its own sidebar), the bar can't go there on small screens. collapse on <ui-header-nav> keeps it instead: below 1056px it becomes a menu button that opens the bar as a sheet under the header, down to the bottom of the window, and each mega menu is an accordion row. While the sheet is open, the page behind can't be reached with Tab and doesn't scroll; Esc or following a link closes it, and focus goes back to the button. Make the window narrower than 1056px to see it.
Every link of the shell (the name, menu items, side nav links, switcher items) is an <a> inside the element. On a plain click it first fires ui-navigate with detail.href; it bubbles and is cancelable. Cancel it and give the path to your router: the page doesn't reload. Ctrl / ⌘-click, middle click and target="_blank" stay plain links. This docs site routes its own side nav this way.
ContractsDashboardOpenAwaiting signatureSettings
Dashboard
Last ui-navigate:
HTMLReactReact + Tailwind<divid="ui-shell-routing"style="transform: translateZ(0); position: relative; height: 360px; overflow: hidden; border: 1px solid var(--ui-hairline)">
<template>
<ui-headerlabel="Metro Contracts">
<ui-header-menu-button></ui-header-menu-button>
<ui-header-namehref="#dashboard"prefix="Metro">Contracts</ui-header-name>
</ui-header>
<ui-side-navfixedexpandedlabel="Sections">
<ui-side-nav-items>
<ui-side-nav-linkhref="#dashboard"current>Dashboard</ui-side-nav-link>
<ui-side-nav-menulabel="Requests"expanded>
<ui-side-nav-menu-itemhref="#open">Open</ui-side-nav-menu-item>
<ui-side-nav-menu-itemhref="#signing">Awaiting signature</ui-side-nav-menu-item>
</ui-side-nav-menu>
<ui-side-nav-linkhref="#settings">Settings</ui-side-nav-link>
</ui-side-nav-items>
</ui-side-nav>
<ui-contentid="ui-shell-routing-main">
<pid="ui-shell-routing-title"style="margin: 0; font: var(--ui-font-headline)">Dashboard</p>
</ui-content>
</template>
</div>
<p>Last ui-navigate: <outputid="ui-shell-routing-out">none</output></p>
<scripttype="module">
// docs only: the example gets a shadow root of its own (this page has its own shell)const box = document.getElementById('ui-shell-routing');
const shell = box.attachShadow({ mode:'open' });
shell.append(document.importNode(box.querySelector('template').content, true));
// a router stand-in: cancel the navigation, mark the link, swap the headingconst out = document.getElementById('ui-shell-routing-out');
shell.addEventListener('ui-navigate', (event) => {
event.preventDefault();
event.stopPropagation(); // docs only: this page's own router listens on the documentconst { href } = event.detail;
for (const link of shell.querySelectorAll('ui-side-nav-link, ui-side-nav-menu-item')) {
link.current = link.getAttribute('href') === href;
}
const link = shell.querySelector(`ui-side-nav [href="${href}"]`);
shell.getElementById('ui-shell-routing-title').textContent = link?.textContent.trim() ?? href;
out.value = href;
});
</script>const navigate =useNavigate(); // your router'sconst { pathname } =useLocation();
constroute= (event:CustomEvent<{ href:string }>) => {
event.preventDefault();
navigate(event.detail.href);
};
<UiSideNavfixedexpandedlabel="Sections"onUiNavigate={route}>
<UiSideNavItems>
<UiSideNavLinkhref="/"current={pathname ==='/'}>Dashboard</UiSideNavLink>
<UiSideNavMenulabel="Requests"expanded>
<UiSideNavMenuItemhref="/requests/open"current={pathname ==='/requests/open'}>Open</UiSideNavMenuItem>
<UiSideNavMenuItemhref="/requests/signing"current={pathname ==='/requests/signing'}>Awaiting signature</UiSideNavMenuItem>
</UiSideNavMenu>
<UiSideNavLinkhref="/settings"current={pathname ==='/settings'}>Settings</UiSideNavLink>
</UiSideNavItems>
</UiSideNav>const navigate =useNavigate(); // your router'sconst { pathname } =useLocation();
// plain <a> elements: route their clicks (keep Ctrl / ⌘-click for a new tab)constroute= (event:React.MouseEvent<HTMLAnchorElement>) => {
if (event.button !==0|| event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
event.preventDefault();
navigate(event.currentTarget.getAttribute('href') ??'/');
};
<SideNavfixedexpandedaria-label="Sections">
<SideNavItems>
<SideNavLinkhref="/"current={pathname ==='/'} onClick={route}>Dashboard</SideNavLink>
<SideNavMenulabel="Requests"defaultExpanded>
<SideNavMenuItemhref="/requests/open"current={pathname ==='/requests/open'} onClick={route}>Open</SideNavMenuItem>
<SideNavMenuItemhref="/requests/signing"current={pathname ==='/requests/signing'} onClick={route}>Awaiting signature</SideNavMenuItem>
</SideNavMenu>
<SideNavLinkhref="/settings"current={pathname ==='/settings'} onClick={route}>Settings</SideNavLink>
</SideNavItems>
</SideNav>
ui-navigate also bubbles up through <ui-header>, so one listener on a wrapper, or on the document, routes every link of the shell.
Events
The shell reports what the user opens and closes with ui-toggle:
Element
detail
When
ui-header-menu-button
{ active }
The user pressed the hamburger: the state asked for. Cancelable: preventDefault() stops the side nav following it, so you can open your own.
ui-side-nav
{ expanded }
The user opened or closed the side nav (the hamburger, Esc, the overlay, focus leaving)
ui-side-nav-menu
{ expanded }
A side nav menu opened or closed
ui-header-menu
{ open }
A header menu opened or closed
ui-header-panel
{ expanded }
A panel opened or closed
Open and close things below; each event is listed.
ContractsMonthlyYearlyOpenClosed
Use the hamburger, the Reports menu and the Requests menu.
Events:
HTMLReactReact + Tailwind<divid="ui-shell-events"style="transform: translateZ(0); position: relative; height: 320px; overflow: hidden; border: 1px solid var(--ui-hairline)">
<template>
<ui-headerlabel="Metro Contracts">
<ui-header-menu-buttoncollapsible></ui-header-menu-button>
<ui-header-namehref="#home"prefix="Metro">Contracts</ui-header-name>
<ui-header-navlabel="Metro Contracts">
<ui-header-menulabel="Reports">
<ui-header-menu-itemhref="#monthly">Monthly</ui-header-menu-item>
<ui-header-menu-itemhref="#yearly">Yearly</ui-header-menu-item>
</ui-header-menu>
</ui-header-nav>
</ui-header>
<ui-side-navcollapsiblelabel="Sections">
<ui-side-nav-items>
<ui-side-nav-menulabel="Requests">
<ui-side-nav-menu-itemhref="#open">Open</ui-side-nav-menu-item>
<ui-side-nav-menu-itemhref="#closed">Closed</ui-side-nav-menu-item>
</ui-side-nav-menu>
</ui-side-nav-items>
</ui-side-nav>
<ui-contentid="ui-shell-events-main">
<pstyle="margin: 0; font: var(--ui-font-body)">Use the hamburger, the Reports menu and the Requests menu.</p>
</ui-content>
</template>
</div>
<p>Events: <outputid="ui-shell-events-out">none yet</output></p>
<scripttype="module">
// docs only: the example gets a shadow root of its own (this page has its own shell)const box = document.getElementById('ui-shell-events');
const shell = box.attachShadow({ mode:'open' });
shell.append(document.importNode(box.querySelector('template').content, true));
shell.addEventListener('ui-navigate', (event) => {
event.preventDefault(); // stay on this page
event.stopPropagation();
});
const out = document.getElementById('ui-shell-events-out');
const seen = [];
shell.addEventListener('ui-toggle', (event) => {
seen.unshift(`${event.target.localName} ${JSON.stringify(event.detail)}`);
out.value = seen.slice(0, 3).join(' · ');
});
</script><UiHeaderMenuButtoncollapsibleonUiToggle={(e) => console.log('hamburger', e.detail.active)} />
<UiHeaderMenulabel="Reports"onUiToggle={(e) => console.log('Reports', e.detail.open)}>…</UiHeaderMenu>
<UiSideNavcollapsiblelabel="Sections"onUiToggle={(e) => console.log('side nav', e.detail.expanded)}>
<UiSideNavItems>
<UiSideNavMenulabel="Requests"onUiToggle={(e) => console.log('Requests', e.detail.expanded)}>…</UiSideNavMenu>
</UiSideNavItems>
</UiSideNav><HeaderMenuButtoncollapsibleactive={navOpen} onToggle={setNavOpen} />
<HeaderMenulabel="Reports"onToggle={(open) => console.log('Reports', open)}>…</HeaderMenu>
<SideNavcollapsiblearia-label="Sections"expanded={navOpen} onToggle={setNavOpen}>
<SideNavItems>
<SideNavMenulabel="Requests"onToggle={(expanded) => console.log('Requests', expanded)}>…</SideNavMenu>
</SideNavItems>
</SideNav>
In React + Tailwind the state is yours: onToggle on HeaderMenuButton and SideNav asks for the new state, and nothing changes until you pass it back.
Skip to content
<ui-skip-to-content> goes first in the header. It is hidden until the first Tab on the page, then shows "Skip to main content" (in Thai with lang="th") and jumps to href, #main-content by default: the id <ui-content> gives itself. Press Tab right after this page loads to see the site's own. Inside a shadow root (a micro app), the link finds its target there.
Keyboard
Key
Where
Does
Tab
First stop on the page
Shows the skip link
Enter, Space
Hamburger
Opens or closes the side nav
Enter, Space
Header menu title
Opens or closes the menu
Esc
Header menu
Closes it, focus back on its title
Esc
Header panel
Closes it, focus back on its global action
Esc
Side nav (opened by the hamburger)
Closes it, focus back on the hamburger
Tab
Out of an open panel, header menu, or a side nav over the page
Closes it
Enter, Space
Mega menu entry
Opens or closes its panel
↓
Mega menu entry
Opens the panel, focus on its first link
Esc
Mega menu panel
Closes it, focus back on its entry
Esc
Collapsed bar's sheet
Closes it, focus back on its menu button
Enter
Side nav menu title (a button)
Opens or closes the menu
Accessibility
<ui-header> is the banner landmark, named by label. <ui-header-nav> is a navigation landmark ("Main navigation" unless label says otherwise), <ui-side-nav> another ("Side navigation"), and <ui-content> is main.
current sets aria-current="page" on the link; selected does the same on a switcher item.
The hamburger is named "Open menu" / "Close menu" by its state (open-label / close-label change the words) and reports aria-expanded.
A global action is named by label, through its tooltip. With panel it reports aria-expanded, else aria-pressed while active.
A closed side nav (not a rail) is inert: its links leave the Tab order.
Header menus and side nav menus are disclosures (aria-expanded, aria-controls), not ARIA menus: the links stay links, and Tab moves through them.
A mega menu is a disclosure too (aria-expanded, aria-controls); each group is a list named by its heading. The collapsed bar's menu button is named "Open menu" / "Close menu" and reports aria-expanded; while its sheet is open the rest of the page is inert.
Id of the <ui-header-panel> this action opens. Clicking toggles the panel, active follows it, and the button reports aria-expanded (a disclosure) instead of aria-pressed (a toggle). The button has an explicit tabindex, as Carbon's (cds-button): Safari then focuses it on click and Tab reaches it.
Slots
Slot
Description
(default)
20px icon
CSS parts
Part
Description
base
The button
CSS custom properties
Custom property
Default
Description
--ui-header-action-radius
Corners of the button's hover fill and focus box (default 0; Kanok: 6px)
<ui-header-panel> · React UiHeaderPanel
Attributes
Attribute
Property
Type
Default
Description
expanded
expanded
boolean
false
label
label
string
''
Events
Event
React
Description
ui-toggle
onUiToggle
detail: { expanded }
Slots
Slot
Description
(default)
Panel content (e.g. <ui-switcher>)
CSS parts
Part
Description
base
The panel
<ui-switcher> · React UiSwitcher
Attributes
Attribute
Property
Type
Default
Description
label
label
string
''
Slots
Slot
Description
(default)
<ui-switcher-item> and <hr> elements
<ui-switcher-item> · React UiSwitcherItem
Attributes
Attribute
Property
Type
Default
Description
href
href
string
'#'
selected
selected
boolean
false
target
target
string
''
Where the link opens (_blank for a new tab), as on <a>.
rel
rel
string
''
The link's relation (noopener, external …), as on <a>.
Events
Event
React
Description
ui-navigate
none (use a ref)
detail: { href } (cancelable) on a plain click of the link; cancel it to route client-side (README: SPA router)
Slots
Slot
Description
(default)
Link text
<ui-side-nav> · React UiSideNav
Attributes
Attribute
Property
Type
Default
Description
expanded
expanded
boolean
false
rail
rail
boolean
false
48px icon rail that expands on hover / focus.
fixed
fixed
boolean
false
With expanded: always 256px wide, pushing <ui-content> aside (no overlay). Set both — without expanded the nav slides out of view while <ui-content> keeps its 256px offset.
collapsible
collapsible
boolean
false
Closed on large screens too until the hamburger opens it over the page (Carbon isPersistent={false}); <ui-content> isn't pushed aside.
label
label
string
''
Events
Event
React
Description
ui-toggle
onUiToggle
detail: { expanded } after a user action changed the state
Where the link opens (_blank for a new tab), as on <a>.
rel
rel
string
''
The link's relation (noopener, external …), as on <a>.
large
large
boolean
false
48px row.
Events
Event
React
Description
ui-navigate
none (use a ref)
detail: { href } (cancelable) on a plain click of the link; cancel it to route client-side (README: SPA router)
Slots
Slot
Description
(default)
Link text
icon
16px icon
CSS parts
Part
Description
base
The link
CSS custom properties
Custom property
Default
Description
--ui-nav-item-inset
Space each side of a row (default 0; Kanok: 8px)
--ui-nav-item-radius
Corner radius of a row (default 0; Kanok: 6px)
--ui-nav-current-background
Fill of the current page's row (default --ui-canvas-selected)
--ui-nav-current-mark
Colour of its start-edge bar (default --ui-primary; Kanok: --ui-border-interactive)
--ui-nav-current-mark-width
/ --ui-nav-current-mark-inset / --ui-nav-current-mark-radius - The bar's width (3px; Kanok: 0, the tinted row alone — forced colours still show it), top and bottom inset (0) and corners (0)
<ui-side-nav-menu> · React UiSideNavMenu
Attributes
Attribute
Property
Type
Default
Description
label
label
string
''
expanded
expanded
boolean
false
large
large
boolean
false
Events
Event
React
Description
ui-toggle
onUiToggle
detail: { expanded }
Slots
Slot
Description
(default)
<ui-side-nav-menu-item> elements
icon
16px icon
CSS parts
Part
Description
trigger
The title button
menu
The list of items
CSS custom properties
Custom property
Default
Description
--ui-nav-item-inset
/ --ui-nav-item-radius / --ui-nav-current-* - As on <ui-side-nav-link>
<ui-side-nav-menu-item> · React UiSideNavMenuItem
Attributes
Attribute
Property
Type
Default
Description
href
href
string
'#'
current
current
boolean
false
target
target
string
''
Where the link opens (_blank for a new tab), as on <a>.
rel
rel
string
''
The link's relation (noopener, external …), as on <a>.
Events
Event
React
Description
ui-navigate
none (use a ref)
detail: { href } (cancelable) on a plain click of the link; cancel it to route client-side (README: SPA router)
Slots
Slot
Description
(default)
Link text
CSS parts
Part
Description
base
The link
CSS custom properties
Custom property
Default
Description
--ui-nav-item-inset
/ --ui-nav-item-radius / --ui-nav-current-* - As on <ui-side-nav-link>