@vigdx/ui v2.2.0 on npm (opens in a new tab)

App shell

The frame around every page: a vig-sidebar that collapses to an icon rail and becomes a drawer on phones, a top bar, and a vig-command-menu (Cmd+K / Ctrl+K) that goes to any page, remembers recent commands and searches the server.

Live demo

Pick a page in the sidebar, collapse it with the trigger (reload: it stays collapsed), or open the command menu with the Search button and type “sales” or a name such as “grace”. On this site Ctrl K opens the site search, so the demo opens its menu from the button.

Northwind

Dashboard

Content of the Dashboard page. Press Ctrl K (⌘K on a Mac) or the search button to jump anywhere.

Dashboard
Inbox
Documents
Sales
Customers
Collapse sidebar

The frame around every page of an application: a sidebar with the navigation, a top bar and a Cmd+K / Ctrl+K command menu, rendered once by a layout route while the pages change below it. The sidebar collapses to an icon rail on wide screens, and the choice is remembered; on narrow screens it becomes a drawer. The command menu goes to any page, runs the shell's actions and searches people on the server.

When to use

  • Back-office and SaaS applications with more than a handful of pages: one navigation, always in the same place.
  • Users who return daily and benefit from keyboard access: the command menu reaches any page in a few keystrokes.
  • For a public site with a few top-level pages, use a header navigation instead; for a single screen, no shell at all.

Component choices

Need Component Why Alternatives
Navigation vig-sidebar with vig-sidebar-nav , groups and items A <nav> landmark of real links; groups label and fold sections; the current page gets aria-current="page"vig-tabs for two to five sibling views of one page
Collapse and mobile [(collapsed)] and the sidebar's drawer layout One component: an icon rail with tooltips on wide screens, a native modal drawer below the breakpoint —
Sidebar toggle <button vigSidebarTrigger> Named, with aria-expanded and aria-controls ; collapses the rail or opens the drawer, whichever applies; gets focus when a layout switch leaves it nowhere Call the sidebar's toggle() from your own control
Jump anywhere vig-command-menu A combobox over a listbox in a modal dialog (APG), locale-aware filtering, recent commands, async results with abort vig-autocomplete for search inside one page
Current page from the router routerLinkActive with ariaCurrentWhenActive="page" The router sets aria-current , the kit styles it; the kit needs no router dependency Bind [attr.aria-current] yourself

Folder structure

Angular CLI

Text
src/app/shell/
  data-access/
    shell-nav.ts               the navigation as data, shared by sidebar and command menu
    shell-preferences.ts       collapsed sidebar and recent commands in localStorage
    people-search.ts           the server search the command menu calls
  feature/
    app-shell.ts               layout: sidebar, top bar, content, command menu
    app-shell.routes.ts        the layout route with the pages as children
    shell-page.ts              stand-in page
  ui/
    shell-sidebar-nav.ts       sections and links with routerLink
    top-bar.ts                 trigger, title and the search button
app.routes.ts
export const routes: Routes = [{ path: '', children: appShellRoutes }];

Route data reaches the components as inputs through withComponentInputBinding() in provideRouter . Make the shell fill the window: it is h-dvh by default.

Nx

Terminal
npx nx g @nx/angular:library --directory=libs/shell/data-access --name=shell-data-access --tags=type:data-access,scope:shell --prefix=app --no-interactive
npx nx g @nx/angular:library --directory=libs/shell/feature --name=shell-feature --tags=type:feature,scope:shell --prefix=app --no-interactive
npx nx g @nx/angular:library --directory=libs/shell/ui --name=shell-ui --tags=type:ui,scope:shell --prefix=app --no-interactive

Key decisions

  • One navigation model. SHELL_NAV is plain data: the sidebar renders it and every link becomes a "Go to" command, so the two never drift apart. The routes are built from it too.
  • The router marks the current page. Each item is an <a routerLink> with routerLinkActive and ariaCurrentWhenActive="page" ; the kit styles aria-current , so it needs no router of its own. The start page uses exact matching, or it would stay current on every page.
  • Persistence belongs to the app. vig-sidebar only has a collapsed model. ShellPreferences keeps it, and the recent command ids, in localStorage , restored after the first render: the server always renders the expanded sidebar, so hydration never sees a mismatch. Until that state has rendered the sidebar's width transition is off ( [style.transition] ), so a collapsed rail does not slide shut on every load. For a server render that already shows the stored state, keep it in a cookie instead and read it on the server through the REQUEST token.
  • No flash on phones. Until the browser measures the viewport the sidebar's layout is pending : it renders inline, and below the default 48rem breakpoint CSS hides it, so the server's HTML neither flashes the inline panel on a phone nor shifts the layout on a desktop. With another breakpoint , add the same rule for [data-scope='sidebar'][data-part='root'][data-layout='pending'] .
  • Recent commands from `executed`. The menu emits the command that ran; the app records its id and passes the list back as recent , shown while the field is empty.
  • Server search with abort. search returns a promise and receives an AbortSignal . The menu waits for typing to pause and aborts the previous call when the query changes, so a slow answer never replaces a newer one. Pass the signal on to fetch or HttpClient .
  • One shortcut listener. The menu registers Cmd+K / Ctrl+K through the kit's shared listener; a second palette or a page's own shortcut does not add another document listener.

Accessibility

  • The sidebar is a <nav> landmark named "Main"; the content is the page's <main> .
  • Items are links (or buttons for actions) with visible text. On the collapsed rail the text is visually hidden but still names the item, and a tooltip shows it on hover and focus.
  • The current page has aria-current="page" and is shown by weight and a start-edge bar, not by color alone, so it survives forced-colors mode.
  • Collapsible groups are disclosure buttons with aria-expanded and aria-controls .
  • The trigger has aria-expanded and aria-controls . On narrow screens the drawer is a native modal dialog: focus moves in, Escape closes it, and focus returns to the trigger; following a link closes it too. Crossing the breakpoint keeps focus on the item, or moves it to the trigger.
  • The command menu follows the APG combobox pattern; Enter is ignored while an IME composes text, and the result count is announced once typing pauses. The search button names its shortcut with aria-keyshortcuts .
  • The width animation of the rail is skipped when the user prefers reduced motion.

Performance

  • The shell renders once; only the routed page changes below it.
  • Pages are lazy routes; the shell itself can be eager, since every page needs it.
  • OnPush everywhere; the command list is a computed of the navigation and the sidebar state.
  • The server search runs only after a pause in typing and cancels stale requests.

Definition of done

  • nx build <app> (or ng build ) succeeds; nx lint passes.
  • The specs pass: navigation and the current page, opening the menu, going to a page, server search, recent commands, collapsing from a command and remembering it.
  • axe reports no violations with the sidebar expanded, collapsed and as an open drawer, and with the command menu open, light and dark.
  • Keyboard only: reach every page from the sidebar, collapse it, open the menu with Ctrl+K, run a command with Enter, close the drawer with Escape and land on the trigger.
  • Reload keeps the collapsed state; the server HTML shows the expanded sidebar.

Source files

Are you sure?