Search
MaterialComponentsDocs
Components overviewApp barBadgeButtonsButton groupButtonExtended FABFAB menuFABIcon buttonSplit buttonCardCarouselCheckboxChipsDate & time pickersDate pickerTime pickerDialogDividerListLoading & progressLoading indicatorProgressMenuNavigationNavigation barNavigation drawerNavigation railRadio buttonsSearchSelectSheetsBottom sheetSide sheetSliderSnackbarSwitchTabsText fieldToolbarTooltip

Navigation drawer

Explore a navigation drawer with destinations, section labels, and badges.

Your mailboxInboxFavoritesSent
FactoryWeb ComponentsReactVueSvelteSolidJS
PublishedUpdated

A navigation drawer holds an app's top-level destinations in a vertical list along one edge, with dividers, section labels and expandable sections to group them. A destination is a button, or a native link when it has an href. M3 has two: standard, inline in the layout of an expanded window, and modal, over the page behind a scrim, for compact and medium windows. For content rather than destinations, use a sheet; for a short list of actions, a menu.

Usage

items are destinations, dividers (type: 'divider') and section labels (type: 'section'); active marks the current destination, and a badge is trailing text such as an unread count. activeIcon is the icon shown while that destination is selected. The web component takes it as selected-icon.

Vanilla
import { createNavigationDrawer } from 'material';

const drawer = createNavigationDrawer({
  headline: 'Mail',
  open: true,
  items: [
    {
      id: 'inbox',
      label: 'Inbox',
      icon: inboxIcon,
      badge: '24',
      active: true,
    },
    { id: 'outbox', label: 'Outbox', icon: outboxIcon },
    { type: 'divider' },
    { type: 'section', label: 'Labels' },
    { id: 'family', label: 'Family', icon: labelIcon },
  ],
});
document.body.append(drawer.element);
Web Components
<m-drawer value="inbox" open headline="Mail">
  <m-drawer-item value="inbox" badge="24">Inbox</m-drawer-item>
  <m-drawer-item value="outbox">Outbox</m-drawer-item>
  <m-drawer-item type="divider"></m-drawer-item>
  <m-drawer-item type="section">Labels</m-drawer-item>
  <m-drawer-item value="family">Family</m-drawer-item>
</m-drawer>

<script type="module">
  const drawer = document.querySelector('m-drawer');
  drawer.querySelector('m-drawer-item[value="inbox"]').setAttribute('icon', inboxIcon);
  drawer.querySelector('m-drawer-item[value="outbox"]').setAttribute('icon', outboxIcon);
  drawer.querySelector('m-drawer-item[value="family"]').setAttribute('icon', labelIcon);
</script>
React
import { useState } from 'react';
import { Drawer, DrawerItem } from 'material/react';
import { inboxIcon, outboxIcon, labelIcon } from './app';

export function Example() {
  const [value, setValue] = useState("inbox");
  return (
    <Drawer value={value} onChange={(event) => setValue(event.detail.value)} open headline="Mail">
      <DrawerItem value="inbox" icon={inboxIcon} badge="24">Inbox</DrawerItem>
      <DrawerItem value="outbox" icon={outboxIcon}>Outbox</DrawerItem>
      <DrawerItem type="divider" />
      <DrawerItem type="section">Labels</DrawerItem>
      <DrawerItem value="family" icon={labelIcon}>Family</DrawerItem>
    </Drawer>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MDrawer, MDrawerItem } from 'material/vue';
import { inboxIcon, outboxIcon, labelIcon } from './app';

const value = ref("inbox");
</script>

<template>
  <MDrawer v-model="value" open headline="Mail">
    <MDrawerItem value="inbox" :icon="inboxIcon" badge="24">Inbox</MDrawerItem>
    <MDrawerItem value="outbox" :icon="outboxIcon">Outbox</MDrawerItem>
    <MDrawerItem type="divider" />
    <MDrawerItem type="section">Labels</MDrawerItem>
    <MDrawerItem value="family" :icon="labelIcon">Family</MDrawerItem>
  </MDrawer>
</template>
Svelte
<script lang="ts">
  import { Drawer, DrawerItem } from 'material/svelte';
  import { inboxIcon, outboxIcon, labelIcon } from './app';

  let value = $state("inbox");
</script>

<Drawer bind:value open headline="Mail">
  <DrawerItem value="inbox" icon={inboxIcon} badge="24">Inbox</DrawerItem>
  <DrawerItem value="outbox" icon={outboxIcon}>Outbox</DrawerItem>
  <DrawerItem type="divider" />
  <DrawerItem type="section">Labels</DrawerItem>
  <DrawerItem value="family" icon={labelIcon}>Family</DrawerItem>
</Drawer>
SolidJS
import { createSignal } from 'solid-js';
import { Drawer, DrawerItem } from 'material/solid';
import { inboxIcon, outboxIcon, labelIcon } from './app';

export function Example() {
  const [value, setValue] = createSignal("inbox");
  return (
    <Drawer value={value()} onChange={(event) => setValue(event.detail.value)} open headline="Mail">
      <DrawerItem value="inbox" icon={inboxIcon} badge="24">Inbox</DrawerItem>
      <DrawerItem value="outbox" icon={outboxIcon}>Outbox</DrawerItem>
      <DrawerItem type="divider" />
      <DrawerItem type="section">Labels</DrawerItem>
      <DrawerItem value="family" icon={labelIcon}>Family</DrawerItem>
    </Drawer>
  );
}

Examples

A destination with an href is a real <a>: it navigates, it can be opened in a new tab, and the current one carries aria-current="page" — server-rendered drawers expose the links before client JavaScript loads.

Vanilla
import { createNavigationDrawer } from 'material';

const drawer = createNavigationDrawer({
  open: true,
  headline: 'Workspace',
  items: [
    {
      id: 'home',
      label: 'Home',
      icon: homeIcon,
      href: '/',
      active: true,
    },
    {
      id: 'projects',
      label: 'Projects',
      icon: inboxIcon,
      href: '/showcase/',
    },
    {
      id: 'settings',
      label: 'Settings',
      icon: settingsIcon,
      href: '/styles/',
    },
  ],
});
document.body.append(drawer.element);
Web Components
<m-drawer value="home" open headline="Workspace">
  <m-drawer-item value="home" href="/">Home</m-drawer-item>
  <m-drawer-item value="projects" href="/showcase/">Projects</m-drawer-item>
  <m-drawer-item value="settings" href="/styles/">Settings</m-drawer-item>
</m-drawer>

<script type="module">
  const drawer = document.querySelector('m-drawer');
  drawer.querySelector('m-drawer-item[value="home"]').setAttribute('icon', homeIcon);
  drawer.querySelector('m-drawer-item[value="projects"]').setAttribute('icon', inboxIcon);
  drawer.querySelector('m-drawer-item[value="settings"]').setAttribute('icon', settingsIcon);
</script>
React
import { useState } from 'react';
import { Drawer, DrawerItem } from 'material/react';
import { homeIcon, inboxIcon, settingsIcon } from './app';

export function Example() {
  const [value, setValue] = useState("home");
  return (
    <Drawer value={value} onChange={(event) => setValue(event.detail.value)} open headline="Workspace">
      <DrawerItem value="home" icon={homeIcon} href="/">Home</DrawerItem>
      <DrawerItem value="projects" icon={inboxIcon} href="/showcase/">Projects</DrawerItem>
      <DrawerItem value="settings" icon={settingsIcon} href="/styles/">Settings</DrawerItem>
    </Drawer>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MDrawer, MDrawerItem } from 'material/vue';
import { homeIcon, inboxIcon, settingsIcon } from './app';

const value = ref("home");
</script>

<template>
  <MDrawer v-model="value" open headline="Workspace">
    <MDrawerItem value="home" :icon="homeIcon" href="/">Home</MDrawerItem>
    <MDrawerItem value="projects" :icon="inboxIcon" href="/showcase/">Projects</MDrawerItem>
    <MDrawerItem value="settings" :icon="settingsIcon" href="/styles/">Settings</MDrawerItem>
  </MDrawer>
</template>
Svelte
<script lang="ts">
  import { Drawer, DrawerItem } from 'material/svelte';
  import { homeIcon, inboxIcon, settingsIcon } from './app';

  let value = $state("home");
</script>

<Drawer bind:value open headline="Workspace">
  <DrawerItem value="home" icon={homeIcon} href="/">Home</DrawerItem>
  <DrawerItem value="projects" icon={inboxIcon} href="/showcase/">Projects</DrawerItem>
  <DrawerItem value="settings" icon={settingsIcon} href="/styles/">Settings</DrawerItem>
</Drawer>
SolidJS
import { createSignal } from 'solid-js';
import { Drawer, DrawerItem } from 'material/solid';
import { homeIcon, inboxIcon, settingsIcon } from './app';

export function Example() {
  const [value, setValue] = createSignal("home");
  return (
    <Drawer value={value()} onChange={(event) => setValue(event.detail.value)} open headline="Workspace">
      <DrawerItem value="home" icon={homeIcon} href="/">Home</DrawerItem>
      <DrawerItem value="projects" icon={inboxIcon} href="/showcase/">Projects</DrawerItem>
      <DrawerItem value="settings" icon={settingsIcon} href="/styles/">Settings</DrawerItem>
    </Drawer>
  );
}

A destination with an items list is an expandable section: its own row is the toggle, its children are nested destinations, and a section opens by itself to reveal the destination made active.

import { createNavigationDrawer } from 'material/components/drawer';

const drawer = createNavigationDrawer({
  headline: 'Workspace',
  items: [
    { id: 'home', label: 'Home', icon: homeIcon, href: '/' },
    {
      id: 'projects',
      label: 'Projects',
      icon: inboxIcon,
      expanded: true,
      items: [
        { id: 'active', label: 'Active', href: '/showcase/' },
        { id: 'archived', label: 'Archived', href: '/docs/' },
      ],
    },
  ],
});
drawer.expandSection('projects');
document.body.append(drawer.element);

A modal drawer opens over the page and locks it: the page does not scroll, and focus moves to the active destination. The scrim and Escape close it; dismissible: false keeps it open.

Vanilla
import { createNavigationDrawer } from 'material';

const drawer = createNavigationDrawer({
  variant: 'modal',
  headline: 'Mail',
  items: [
    { id: 'inbox', label: 'Inbox', icon: inboxIcon, active: true },
    { id: 'outbox', label: 'Outbox', icon: outboxIcon },
  ],
});
document.body.append(drawer.element);

function openNavigation() {
  drawer.open();
}
Web Components
<m-drawer value="inbox" headline="Mail" modal>
  <m-drawer-item value="inbox">Inbox</m-drawer-item>
  <m-drawer-item value="outbox">Outbox</m-drawer-item>
</m-drawer>

<script type="module">
  const drawer = document.querySelector('m-drawer');
  drawer.querySelector('m-drawer-item[value="inbox"]').setAttribute('icon', inboxIcon);
  drawer.querySelector('m-drawer-item[value="outbox"]').setAttribute('icon', outboxIcon);

  function openNavigation() {
    drawer.open = true;
  }
</script>
React
import { useState } from 'react';
import { Drawer, DrawerItem } from 'material/react';
import { inboxIcon, outboxIcon } from './app';

export function Example() {
  const [value, setValue] = useState("inbox");
  const [open, setOpen] = useState(false);
  const openNavigation = () => setOpen(true);

  return (
    <Drawer value={value} onChange={(event) => setValue(event.detail.value)} open={open} onClose={() => setOpen(false)} headline="Mail" modal>
      <DrawerItem value="inbox" icon={inboxIcon}>Inbox</DrawerItem>
      <DrawerItem value="outbox" icon={outboxIcon}>Outbox</DrawerItem>
    </Drawer>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MDrawer, MDrawerItem } from 'material/vue';
import { inboxIcon, outboxIcon } from './app';

const value = ref("inbox");
const open = ref(false);

function openNavigation() {
  open.value = true;
}
</script>

<template>
  <MDrawer v-model="value" :open="open" @close="open = false" headline="Mail" modal>
    <MDrawerItem value="inbox" :icon="inboxIcon">Inbox</MDrawerItem>
    <MDrawerItem value="outbox" :icon="outboxIcon">Outbox</MDrawerItem>
  </MDrawer>
</template>
Svelte
<script lang="ts">
  import { Drawer, DrawerItem } from 'material/svelte';
  import { inboxIcon, outboxIcon } from './app';

  let value = $state("inbox");
  let open = $state(false);

  function openNavigation() {
    open = true;
  }
</script>

<Drawer bind:value open={open} onclose={() => (open = false)} headline="Mail" modal>
  <DrawerItem value="inbox" icon={inboxIcon}>Inbox</DrawerItem>
  <DrawerItem value="outbox" icon={outboxIcon}>Outbox</DrawerItem>
</Drawer>
SolidJS
import { createSignal } from 'solid-js';
import { Drawer, DrawerItem } from 'material/solid';
import { inboxIcon, outboxIcon } from './app';

export function Example() {
  const [value, setValue] = createSignal("inbox");
  const [open, setOpen] = createSignal(false);
  const openNavigation = () => setOpen(true);

  return (
    <Drawer value={value()} onChange={(event) => setValue(event.detail.value)} open={open()} onClose={() => setOpen(false)} headline="Mail" modal>
      <DrawerItem value="inbox" icon={inboxIcon}>Inbox</DrawerItem>
      <DrawerItem value="outbox" icon={outboxIcon}>Outbox</DrawerItem>
    </Drawer>
  );
}

With layer: 'top', a modal drawer is a native <dialog> in the top layer, above every z-index and outside any clipping ancestor, and its scrim is the ::backdrop. The web component's modal drawer is always in the top layer.

Dense, at the end

dense is the fifth step (-5, 36dp item height with a 48dp touch target, keeping typography, 24dp icons, badges, dividers and the 12px 0 sheet padding unchanged) on the --mtrl-density scale; position: 'end' anchors the drawer to the end edge, which is the left in right-to-left layouts. width is pixels as a number, or any CSS length.

Vanilla
import { createNavigationDrawer } from 'material';

const drawer = createNavigationDrawer({
  open: true,
  dense: true,
  position: 'end',
  width: 280,
  items: [
    { id: 'users', label: 'Users', active: true },
    { id: 'billing', label: 'Billing' },
    { id: 'audit', label: 'Audit log' },
  ],
});
document.body.append(drawer.element);
Web Components
<m-drawer value="users" open position="end" width="280" dense>
  <m-drawer-item value="users">Users</m-drawer-item>
  <m-drawer-item value="billing">Billing</m-drawer-item>
  <m-drawer-item value="audit">Audit log</m-drawer-item>
</m-drawer>
React
import { useState } from 'react';
import { Drawer, DrawerItem } from 'material/react';

export function Example() {
  const [value, setValue] = useState("users");
  return (
    <Drawer value={value} onChange={(event) => setValue(event.detail.value)} open position="end" width="280" dense>
      <DrawerItem value="users">Users</DrawerItem>
      <DrawerItem value="billing">Billing</DrawerItem>
      <DrawerItem value="audit">Audit log</DrawerItem>
    </Drawer>
  );
}
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { MDrawer, MDrawerItem } from 'material/vue';

const value = ref("users");
</script>

<template>
  <MDrawer v-model="value" open position="end" width="280" dense>
    <MDrawerItem value="users">Users</MDrawerItem>
    <MDrawerItem value="billing">Billing</MDrawerItem>
    <MDrawerItem value="audit">Audit log</MDrawerItem>
  </MDrawer>
</template>
Svelte
<script lang="ts">
  import { Drawer, DrawerItem } from 'material/svelte';

  let value = $state("users");
</script>

<Drawer bind:value open position="end" width="280" dense>
  <DrawerItem value="users">Users</DrawerItem>
  <DrawerItem value="billing">Billing</DrawerItem>
  <DrawerItem value="audit">Audit log</DrawerItem>
</Drawer>
SolidJS
import { createSignal } from 'solid-js';
import { Drawer, DrawerItem } from 'material/solid';

export function Example() {
  const [value, setValue] = createSignal("users");
  return (
    <Drawer value={value()} onChange={(event) => setValue(event.detail.value)} open position="end" width="280" dense>
      <DrawerItem value="users">Users</DrawerItem>
      <DrawerItem value="billing">Billing</DrawerItem>
      <DrawerItem value="audit">Audit log</DrawerItem>
    </Drawer>
  );
}

A choice emits select with { id, label, index, originalEvent }, index counting the destinations only; the web component dispatches change with { value }, the destination's id. setActive(), setBadge() and setItems() keep the drawer in step with the app, and emit nothing. Recipes such as a drawer that follows the route, or labels that load late, are planned for Showcase.

API

Options

variant

Inline, or over the page with a scrim

Type'standard' | 'modal'
Default'standard'
position

Which edge it anchors to; mirrors under RTL

Type'start' | 'end'
Default'start'
open

Whether it starts open

Typeboolean
Defaultfalse
dismissible

Whether the scrim and Escape close a modal drawer

Typeboolean
Defaulttrue
layer

A modal drawer in the top layer, as a native <dialog>

Type'top'
Defaultundefined
headline

Text above the destinations

Typestring
Defaultundefined
ariaLabel

The drawer's accessible name

Typestring
Defaultthe headline, or 'Navigation'
items

Destinations, dividers and section labels

TypeNavigationDrawerItemConfig[]
Default[]
width

Width; a number is pixels. Set as --mtrl-drawer-width on the root

Typestring | number
Default360
dense

Step -5 on the --mtrl-density scale (36dp item height with a 48dp hit target; type and 24dp icons stay unchanged)

Typeboolean
Defaultfalse
ripple

Press ripple on items, clipped to the item shape

Typeboolean
Defaulttrue
class

Extra CSS classes

Typestring
Defaultundefined
prefix

Class-name prefix

Typestring
Default'mtrl'
componentName

Component name used in class generation

Typestring
Default'drawer'
onSelect

Called when a destination is chosen

Type(event: DrawerSelectEvent) => void
Defaultundefined
onExpand / onCollapse

Called when a section opens or closes

Type(event: DrawerSectionEvent) => void
Defaultundefined
onOpen / onClose

Called when it opens or closes

Type() => void
Defaultundefined

Items

type

What this entry is

Type'item' | 'divider' | 'section'
Default'item'
id

Identifier, used by setActive, setBadge and the select event

Typestring
Defaultundefined
label

Destination text, and the text of a section

Typestring
Defaultundefined
icon

Leading icon, as an HTML string

Typestring
Defaultundefined
activeIcon

Icon shown while this destination is selected, as an HTML string. The element takes it as selected-icon

Typestring
Defaultundefined
href

Makes the destination a native <a> link instead of a button

Typestring
Defaultundefined
items

A non-empty list makes this destination an expandable section, its children nested destinations

TypeNavigationDrawerItemConfig[]
Defaultundefined
expanded

Whether a section starts expanded — omitted opens the section when one of its children is active; an explicit false stays closed

Typeboolean
Defaultomitted: a child's active decides
badge

Trailing text, such as an unread count

Typestring
Defaultundefined
active

Whether this destination starts selected

Typeboolean
Defaultfalse
disabled

Cannot be clicked or reached by the arrow keys, and carries aria-disabled

Typeboolean
Defaultfalse
sectionLabel

Section text, as an alternative to label

Typestring
Defaultundefined

Methods

open() / close() / toggle()

Opens or closes it; opening moves focus to the active destination, or the first

ReturnsDrawerComponent
isOpen()

Whether it is open

Returnsboolean
setActive(id) / getActive()

The current destination

ReturnsDrawerComponent / string | null
setItems(items) / getItems()

Replaces or reads the whole list

ReturnsDrawerComponent / NavigationDrawerItemConfig[]
setBadge(id, badge)

Sets a badge, or clears it with ''

ReturnsDrawerComponent
expandSection(id) / collapseSection(id) / toggleSection(id)

Opens, closes or flips an expandable section

ReturnsDrawerComponent
isSectionExpanded(id)

Whether a section is open

Returnsboolean
getExpandedSections()

The ids of the expanded sections

Returnsstring[]
setHeadline(text) / getHeadline()

The headline

ReturnsDrawerComponent / string
on(event, handler) / off(event, handler)

Events

ReturnsDrawerComponent
addClass(...classes)

Adds classes to the root

ReturnsDrawerComponent
getClass(name)

A class name with the component prefix

Returnsstring
destroy()

Removes the scrim, unbinds the key handler, restores page scrolling

Returnsvoid

Events

select

A destination was chosen

Payload{ id, value, label, index, originalEvent }
expand / collapse

An expandable section opened or closed; the web component forwards { value, expanded }

Payload{ id, value, label, expanded }
open / close

The drawer opened or closed

Payloadnone

<m-drawer-item> takes value, icon, selected-icon, badge, label, href and disabled, or type for a section or divider; nested <m-drawer-item> elements make it an expandable section, which the expanded attribute starts open.

Styling

width is set inline on the root as --mtrl-drawer-width, which the sheet reads. A standard drawer animates its width between 0 and that, so the page reflows around it; a modal drawer keeps its width and slides its sheet in over the page.

.mtrl-drawer { }                                          /* the root */
.mtrl-drawer--open, .mtrl-drawer--standard, .mtrl-drawer--modal { }
.mtrl-drawer--start, .mtrl-drawer--end, .mtrl-drawer--dense { }
.mtrl-drawer__scrim { }                                   /* modal only; --visible while open */
.mtrl-drawer__sheet { }                                   /* the panel that slides */
.mtrl-drawer__headline, .mtrl-drawer__items { }
.mtrl-drawer__item, .mtrl-drawer__item-icon, .mtrl-drawer__item-label, .mtrl-drawer__item-badge { }
.mtrl-drawer__active-indicator { }                        /* the shape behind the current destination */
.mtrl-drawer__divider, .mtrl-drawer__section-label { }

Measurements

Attribute Value
Width 360dp, and at most the window less 56dp for a modal drawer
Corners 16dp on the edge away from the anchor
Destination 56dp tall, 12dp from the sheet's sides, a 28dp pill; icon 24dp, 12dp before the label
Divider 1dp outline-variant, inset 28dp