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.
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);
<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>
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>
);
}
<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>
<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>
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
Links and expandable sections
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.
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);
<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>
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>
);
}
<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>
<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>
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);
Modal
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.
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();
}
<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>
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>
);
}
<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>
<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>
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.
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);
<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>
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>
);
}
<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>
<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>
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
variantInline, or over the page with a scrim
'standard' | 'modal''standard'positionWhich edge it anchors to; mirrors under RTL
'start' | 'end''start'openWhether it starts open
booleanfalsedismissibleWhether the scrim and Escape close a modal drawer
booleantruelayerA modal drawer in the top layer, as a native <dialog>
'top'undefinedheadlineText above the destinations
stringundefinedariaLabelThe drawer's accessible name
string'Navigation'itemsDestinations, dividers and section labels
NavigationDrawerItemConfig[][]widthWidth; a number is pixels. Set as --mtrl-drawer-width on the root
string | number360denseStep -5 on the --mtrl-density scale (36dp item height with a 48dp hit target; type and 24dp icons stay unchanged)
booleanfalseripplePress ripple on items, clipped to the item shape
booleantrueclassExtra CSS classes
stringundefinedprefixClass-name prefix
string'mtrl'componentNameComponent name used in class generation
string'drawer'onSelectCalled when a destination is chosen
(event: DrawerSelectEvent) => voidundefinedonExpand / onCollapseCalled when a section opens or closes
(event: DrawerSectionEvent) => voidundefinedonOpen / onCloseCalled when it opens or closes
() => voidundefinedItems
typeWhat this entry is
'item' | 'divider' | 'section''item'idIdentifier, used by setActive, setBadge and the select event
stringundefinedlabelDestination text, and the text of a section
stringundefinediconLeading icon, as an HTML string
stringundefinedactiveIconIcon shown while this destination is selected, as an HTML string. The element takes it as selected-icon
stringundefinedhrefMakes the destination a native <a> link instead of a button
stringundefineditemsA non-empty list makes this destination an expandable section, its children nested destinations
NavigationDrawerItemConfig[]undefinedexpandedWhether a section starts expanded — omitted opens the section when one of its children is active; an explicit false stays closed
booleanactive decidesbadgeTrailing text, such as an unread count
stringundefinedactiveWhether this destination starts selected
booleanfalsedisabledCannot be clicked or reached by the arrow keys, and carries aria-disabled
booleanfalsesectionLabelSection text, as an alternative to label
stringundefinedMethods
open() / close() / toggle()Opens or closes it; opening moves focus to the active destination, or the first
DrawerComponentisOpen()Whether it is open
booleansetActive(id) / getActive()The current destination
DrawerComponent / string | nullsetItems(items) / getItems()Replaces or reads the whole list
DrawerComponent / NavigationDrawerItemConfig[]setBadge(id, badge)Sets a badge, or clears it with ''
DrawerComponentexpandSection(id) / collapseSection(id) / toggleSection(id)Opens, closes or flips an expandable section
DrawerComponentisSectionExpanded(id)Whether a section is open
booleangetExpandedSections()The ids of the expanded sections
string[]setHeadline(text) / getHeadline()The headline
DrawerComponent / stringon(event, handler) / off(event, handler)Events
DrawerComponentaddClass(...classes)Adds classes to the root
DrawerComponentgetClass(name)A class name with the component prefix
stringdestroy()Removes the scrim, unbinds the key handler, restores page scrolling
voidEvents
selectA destination was chosen
{ id, value, label, index, originalEvent }expand / collapseAn expandable section opened or closed; the web component forwards { value, expanded }
{ id, value, label, expanded }open / closeThe drawer opened or closed
<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 |