Skip to main content
Login

Sign in to access your account

Drawer - National Design System

A vertical list of links and buttons, with submenus that open in place

Overview

A drawer is a vertical list of links and buttons. An item can hold a submenu: a nested list that opens in place under it. The same list also holds flat links, or notification rows with a title and a description, in one column or in columns. A search box above the list can filter a long menu.

Pick another component when:

  • the list is the site’s main navigation: Main Navigation
  • the list is the site’s main side menu, which collapses to a rail: Side Menu
  • the menu opens from one button, over the page: Dropmenu
  • each item opens a panel of content, not a list of links: Accordion
  • the surface slides in over the page: Panels

Markup

Options
Structure
Size
Search
More
Preview
<nav class="nds-drawer" aria-label="Service menu"> <ul class="nds-drawer-list"> <li> <a href="#" class="nds-btn nds-subtle nds-indicator"> <span class="nds-featured-icon nds-sm"> <i class="hgi hgi-stroke hgi-home-01" aria-hidden="true"></i> </span> <span class="nds-label">Dashboard</span> </a> </li> <li> <button type="button" class="nds-btn nds-subtle nds-menu-btn nds-indicator" aria-expanded="false"> <span class="nds-featured-icon nds-sm"> <i class="hgi hgi-stroke hgi-file-01" aria-hidden="true"></i> </span> <span class="nds-label">Requests</span> </button> <ul> <li> <button type="button" class="nds-btn nds-subtle nds-menu-btn nds-indicator" aria-expanded="false"> <span class="nds-label">Licenses</span> </button> <ul> <li> <a href="#" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label">New license</span> </a> </li> <li data-state="active"> <a href="#" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label">Renew a license</span> </a> </li> </ul> </li> <li> <a href="#" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label">Appointments</span> </a> </li> </ul> </li> <li> <button type="button" class="nds-btn nds-subtle nds-menu-btn nds-indicator" aria-expanded="false"> <span class="nds-featured-icon nds-sm"> <i class="hgi hgi-stroke hgi-settings-01" aria-hidden="true"></i> </span> <span class="nds-label">Settings</span> </button> <ul> <li> <a href="#" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label">Profile</span> </a> </li> <li> <a href="#" class="nds-btn nds-subtle nds-indicator"> <span class="nds-label">Security</span> </a> </li> </ul> </li> <li> <a href="#" class="nds-btn nds-subtle nds-indicator"> <span class="nds-featured-icon nds-sm"> <i class="hgi hgi-stroke hgi-help-circle" aria-hidden="true"></i> </span> <span class="nds-label">Help</span> </a> </li> </ul> </nav>

Behavior

An item opens its submenu when its toggle is a <button> or a link with href="#". A link to a real page goes to that page on click, so a click does not open its submenu. That submenu opens only on the path to the active item, or when the markup opens it. Use a link when the parent item is also a page.

One Open Branch

By default, one submenu is open at each level. When a person opens a submenu, the open one next to it closes, so the tree stays short. The markup can open several submenus at load. They stay open until a person opens another submenu at the same level.

Always Open

data-state="always-open" on .nds-drawer lets each submenu open and close on its own, at every level. Submenus stay open until the person closes them. Pick it when people move between the branches of a tree and want to keep them in view.

Narrow Rows

A Notifications row measures its own width, not the screen. The tag floats at the end of the title’s first line, and a long title wraps under it. Below 400px, a date tile with no size class steps down to SM, so the text keeps its room. A tile with nds-sm or nds-lg keeps its size.

Scrolling List

A Scroll More wrapper around the list holds the drawer to --drawer-max-height. While the list overflows, its end fades and the Show more button shows. The button scrolls the list. At the end, it turns to scroll back up.

data-search adds a search box above the list. The list filters as the user types: an item stays when its label matches, and each submenu with a match opens. A match on a submenu’s own label keeps every item under it. A message shows when nothing matches. When the box is cleared, the submenus that were open before the search open again, and the rest close. The search ignores case and accents, as the Dropmenu search does. data-search-style picks the box’s field style from Forms: darker (the default), lighter or outline.

Built-in Features

  • Auto-initialization

    Every drawer on the page starts by itself. The script finds each item with a submenu and gives its toggle an arrow.

  • Accordion Submenus

    Submenus slide open and closed. They nest to any depth, and each level works the same way.

  • Active Path

    The item marked data-state="active" shows the line beside it, and every submenu above it opens. This happens before the page shows, so people land with the current page in view.

  • Empty State

    A list that can run out of items takes nds-empty. The Empty component shows a placeholder while the list holds no items, and removes it when one arrives.

  • Screen Readers

    The script keeps aria-expanded on each toggle in step with its submenu.

  • JavaScript API

    Open or close a submenu from code, start and stop a drawer, and listen for an event when a submenu has opened or closed.

Best Practices

  • Give the <nav> an aria-label that names the menu. A page often has more than one nav, and the label tells them apart.
  • Put data-state="active" only on the current page’s <li>, never on the items above it.
  • Use nds-indicator on the items of a menu, where it marks the current page. Leave it off a list of links, notices or dated rows.
  • Use a <button type="button"> for an item that only opens a submenu.
  • Keep trees to two or three levels. A deeper tree is hard to scan, and often means the section should be split into pages.
  • Keep labels short. A label wraps to a new line when it is too long.
  • In a Notifications row, put data-status on the <li> and on the tag. The status on the <li> colors the icon. The tag does not take it from the <li>.
  • Leave the size class off the tag in a Notifications row. The drawer makes it XS, so it leaves the title its room.
  • Leave nds-truncate off the title in a Notifications row. A cut title cannot wrap under the tag, so it shows less text.
  • Add search to a menu of about 20 items or more. Use data-search="20" when the item count changes, so a short menu gets no box.
  • Use Divided when rows have two lines. Leave it off a list of short links, where the lines only add noise.
  • For rows in columns, put nds-grid on the list and set the columns as on a Grid. Keep nds-divided on the drawer: the last row draws no line.
  • Make a row a <button> when it opens a panel or a modal on the page, and an <a> when it opens a page.
  • After you add a drawer to the page, call NDS.Drawer.init(). After you change the items of a drawer that started, call NDS.Drawer.destroy(drawer), then NDS.Drawer.create(drawer).

API

Other Classes

Class Element Effect
nds-grid .nds-drawer-list Lays the rows out in columns, with the Grid knobs. The rows keep --drawer-gap, and the columns take the grid’s gap. On a divided drawer, the Grid script marks the last row, which draws no line
nds-fit .nds-drawer inside .nds-grid The drawer fills the height of its grid row, and the items share the height. Use it with nds-card to match the cards next to it. It has no effect outside .nds-grid
nds-oncolor .nds-drawer Lighter divider lines, for a drawer on a colored surface. Its buttons take the on-color look too. Inside an on-color area (data-theme="dark oncolor"), the drawer already takes this look: skip the class
nds-divided a submenu <ul> A line between the items of that submenu
nds-empty .nds-drawer-list Shows a placeholder while the list holds no items. Set the text and the icon with data-empty-message and data-empty-icon. See Empty
nds-truncate .nds-label Cuts the label to the number of lines in --drawer-truncate, with an ellipsis
nds-loading .nds-drawer Shows gray placeholders in place of the content while the data loads. Remove it when the data is in

Data Attributes

Attribute Element Effect
data-state="always-open" .nds-drawer Each submenu opens and closes on its own, at every level. Without it, opening a submenu closes the open one beside it
data-search .nds-drawer Adds a search box above the list. A number, such as data-search="20", adds it only when the drawer has that many items or more
data-search-empty .nds-drawer The text shown when nothing matches. The default is “No results”
data-search-style .nds-drawer The search box’s field style: darker (the default), lighter or outline, as the Forms field styles
data-state="active" <li> Marks the current page. Its line shows, and every submenu above it opens at load. A closed submenu above it keeps its button marked. The script writes aria-current="page" on the <li>’s link and moves it with the mark. It keeps an aria-current you wrote
data-state="open" <li> and its submenu <ul> Opens the submenu at load, before the script runs. Set it on both, with aria-expanded="true" on the toggle button. The script keeps it in step: opening and closing during the slide, open while the submenu is open
data-state="active current" A submenu’s toggle button The script sets active while the submenu is open, or while it holds the current page. It adds current while it holds the current page, which gives the mark the primary color, a lighter primary in dark mode and on color. Leave both to the script
data-status <li> success, info, warning, error or neutral. Colors the featured icon in the row
data-search-value <li> More words the item is found by, such as its name in another language

CSS Custom Properties

Set them on .nds-drawer, in its style attribute.

Property Default Controls
--drawer-gap 0px Space between the items
--drawer-indent var(--spacing-xl), var(--spacing-2xl) with nds-lg Indent of each submenu
--drawer-divider var(--divider-color) Color of the nds-divided and nds-lined lines
--drawer-indicator transparent Color of the line on submenu items that are not active or hovered
--drawer-indicator-width 5px Width of the line beside each item
--drawer-lined-width 1px Width of the nds-lined line
--drawer-lined-block 0px Space cut from the top and the bottom of the nds-lined line
--drawer-truncate 1 Number of lines a nds-truncate label shows
--drawer-transition var(--nds-transition) Timing of the submenu slide
--drawer-max-height 400px Height limit of a Scrolling list
--drawer-btn-height fit-content, 100% with nds-fit Height of each item
--drawer-btn-gap var(--spacing-md) Space between the icon, the label and the end of each item

Tokens

It reads these shared tokens. A change to one also changes other components: see Tokens.

Source: the var() reads in _sass/components/_drawer.scss.

TokenPreviewValue
--text-primary-strong
Read by --btn-color

var(--colors-primary-700)
Dark mode var(--colors-primary-400)
--divider-color
Read by --drawer-divider

var(--colors-alpha-black-10)
Dark mode var(--colors-alpha-white-10)
--button-background-transparent-default
Read by --btn-bg, --btn-bg-selected
var(--colors-alpha-white-0)
--button-indicator-mark
Read by --btn-indicator-selected, --btn-indicator-color

var(--background-primary)
Dark mode var(--colors-primary-500)
--featuredicons-icon-default
Read by --featuredicon-dark-bg-forced

var(--icon-default)
Dark mode var(--colors-neutral-100)
--featuredicons-background-default-light
Read by --featuredicon-bg-forced

var(--colors-neutral-50)
Dark mode var(--colors-alpha-white-10)
--featuredicons-icon-neutral
Read by --featuredicon-color-forced

var(--icon-neutral)
Dark mode var(--colors-neutral-300)

JavaScript

Method Effect
NDS.Drawer.init() Starts every drawer on the page that has not started yet
NDS.Drawer.create(drawer) Starts one drawer. It does nothing on a drawer that has started
NDS.Drawer.toggle(button) Opens or closes the submenu of this toggle button. Pass the button, not the <li>
NDS.Drawer.destroy(drawer) Removes the listeners. The markup and the open submenus stay as they are
Event Fired on Detail
nds:drawer:shown .nds-drawer, after a submenu opens, and it bubbles item (the <li>), drawer
nds:drawer:hidden .nds-drawer, after a submenu closes, and it bubbles item (the <li>), drawer

The events fire when a person or toggle() opens or closes a submenu. They do not fire for the submenus that open at load, or for the submenus a search opens and closes.

var drawer = document.querySelector('.nds-drawer'); drawer.addEventListener('nds:drawer:shown', function (e) { console.log('Opened', e.detail.item); }); NDS.Drawer.toggle(drawer.querySelector('.nds-menu-btn'));

The full API is in the banner of _js/nds-drawer.js.

Last Modified Date: 21/11/2026 - 12:03 AM
Was this page useful?
60% of users said Yes from 2843 Feedbacks