Socket
Socket
Sign inDemoInstall

@material/drawer

Package Overview
Dependencies
13
Maintainers
15
Versions
1683
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @material/drawer

The Material Components Web drawer component


Version published
Weekly downloads
761K
decreased by-17.43%
Maintainers
15
Install size
3.52 MB
Created
Weekly downloads
 

Changelog

Source

14.0.0 (2022-04-27)

Bug Fixes

  • button: update HCM shim to use the existing focus-ring (a657abb)
  • checkbox: Add explicit system color for checkmark in HCM. (8c4da22)
  • checkbox: move forced-colors theme out of static styles (bbd1126)
  • checkbox: Update checkbox theme styles mixin to accept css vars (c14e977)
  • chips: Fix typography selector in GMDC-Wiz chips theming (43c7d87)
  • datatable: Adjust data table last row border-radius to support setting row background-color. (ba78e87)
  • dialog: Render dividers in Firefox 94 on Windows HCM (fae6c65)
  • dialog: Set default z-index for close button in FloatingSheet dialog. (3366a71)
  • fab: Add focus ring in HCM. (d57ec74)
  • focus-ring: add 2d padding customizability, RTL bugfix (f81fb1d)
  • focus-ring: box-sizing bugfix to content-box. If box-sizing border-box is inherited the ring spacing will collapse. (e58552c)
  • focus-ring: ignore pointer events (3ef470e)
  • focus-ring: RTL bugfix (e00181e)
  • iconbutton: Fixed max width and height for high contrast mode focus ring on icon buttons. Display only in forced colors mode. (cf42927)
  • iconbutton: Set icon button ripple z-index to -1. (586e740)
  • list: Improve a11y for multi-select lists (9736ddc)
  • list: Remove conflicting validation for checkbox list in setEnabled (353ca7e)
  • list: Update lastSelectedIndex when toggling a checkbox range (dcba26f)
  • menusurface: Add a getOwnerDocument() method to MDCMenuSurfaceAdapter to provide a reference to the document that owns the menu surface DOM element. (3486659)
  • radio: Fix disabled state in Firefox Windows high contrast mode (23043ac)
  • radio: Modify theme styles Sass mixin validation to validate only keys (390220e)
  • select: Add border to select menu in HCM. (5d80969)
  • select: revert down/up arrow on anchor changing selected index (43d08ba)
  • slider: Fix bug where secondary click moves slider thumb. (3ab9565)
  • slider: Fix IE11 bug - unset is unsupported in IE. (f460e23)
  • slider: In updateUI, fix behavior to match jsdoc claim that when thumb param is undefined it updates both thumbs. Input attributes were not being updated at all. (cc4ed13)
  • slider: Make the slider errors easier to debug by providing all relevant values in the error message. (8687937)
  • snackbar: address Trusted Types violation (cbd9358)
  • tooltip: Adjusts logic in validateTooltipWithCaretDistances method. (3e30054)
  • typography: Fixes typography theme-styles mixin... the value being retreived from the $theme map and css property name was swapped. The mixin would request font-size/font-weight/letter-spacing from the $theme map (which expects size/weight/tracking)... so these values would always be null. (32b3913)
  • Remove /** @override */ tags from TypeScript code. (c3cdff0)
  • Simplify MDCAttachable interface to be any object (Function) that has attachTo. (05db65e)
  • Snackbar action button ripple color is applied to the ripple element. (4e66fb2)
  • Work around bug in Sass (037285f), closes sass/sass#3259
  • switch: Restore Firefox 94 HCM outlines (39cf14b)
  • textfield: Fix breaking tests due to no valid pointerId being associated with pointer events. (15db4f1)
  • tooltip: Only sends notification of a tooltip being hidden if showTimeout is not set (indicating that this tooltip is about to be re-shown). (6ca8b8f)

Features

  • banner: Add disableAutoClose params for both banner actions to prevent the banner buttons from automatically closing the banner. Add adapter #notifyActionClicked method. (b094eaa)
  • chips: add focus ring styles (783f6fd)
  • chips: Added elevation tint layer color support in chips (c78ff04)
  • data-table: separate table structure into its own mixin (9f9d928)
  • dialog: Add styling for floating sheets (78305b6)
  • dialog: Add styling for floating sheets with content padding (3e20c1d)
  • Dialog: Adds an API to hide the header for GMDC Fullscreen Dialog in non-fullscreen mode (ab4aba1)
  • Dialog: Adds an API to set custom position for GMDC Dialog (ea9b5b4)
  • Dialog: Adds an API to set custom z-index for GMDC Dialog (96ea061)
  • focus-ring: added a new mixin so we can override just the focus-ring color (641ed08)
  • focus-ring: added a new mixin so we can override just the focus-ring radius (7321d62)
  • iconbutton: Add link icon button Sass. (9803d2d)
  • mdc-list: introduce selection change event (7d8ea46)
  • menu: allow preferentially opening surface below anchor (261f2db)
  • MenuSurface: Add opening event for menus. (53b3cad)
  • select: Add theming mixin boilerplate code to select (ae8a6a3)
  • select: Add validation getter methods. (bdf1d37)
  • select: Added theme mixins to MDC select (dcfe49c)
  • slider: Add minRange param to range sliders to request a minimum gap between the two thumbs. (8fffcb5)
  • slider: Add an option to hide focus styles after pointer interaction. (ec54d90)
  • slider: Keep the slider value indicator within the bounds of the slider if possible. (c047f7c)
  • state: make context aware (b2fe352)
  • switch: Add high contrast mode focus ring to switch (f31a833)
  • text-field: Add theming mixin boilerplate code to text-field (eb382f3)
  • text-field: Added theme mixins to MDC text field (344d528)
  • textfield: adding input-font-size mixin (207230e)
  • theme: allow custom property strings in theme.validate-theme() (4e372fb)
  • add new class and mixin for open state of a menu item (9a02b6e)
  • Indicate which thumb valueToAriaValueTextFn and valueToValueIndicatorTextFn functions are called for. (b6510c8)
  • textfield: adding input-font-family mixin (991fb99)
  • Describe how to add child lists into a list item. (758ce31)

BREAKING CHANGES

  • MenuSurface: Adds #notifyOpening method to menu surface adapter.

PiperOrigin-RevId: 444830518

  • slider: Adds #getValueIndicatorContainerWidth method to slider adapter.

PiperOrigin-RevId: 419837612

Readme

Source

Navigation drawers

Navigation drawers provide access to destinations in your app.

Hero navigation drawer image

Contents

Using navigation drawers

A navigation drawer provides access to destinations and app functionality, such as switching accounts. It can either be permanently on-screen or controlled by a navigation menu icon.

A navigation drawer is recommended for:

  • Apps with five or more top-level destinations
  • Apps with two or more levels of navigation hierarchy
  • Quick navigation between unrelated destinations

Important Changes

Drawer is currently being updated to use the new List implementation. For now, please continue to use the old implementation (mdc-deprecated-list and associated DOM/classes) instead of the new one (mdc-list).

See the List documentation for more information.

Installation

npm install @material/drawer

Styles

@use "@material/drawer";
@use "@material/list";

@include drawer.core-styles;
@include drawer.dismissible-core-styles;
@include drawer.modal-core-styles;
@include list.deprecated-core-styles;

JavaScript instantiation

For permanently visible drawer, the list must be instantiated for appropriate keyboard interaction:

import {MDCList} from "@material/list";
const list = MDCList.attachTo(document.querySelector('.mdc-deprecated-list'));
list.wrapFocus = true;

Other variants use the MDCDrawer component, which will instantiate MDCList automatically:

import {MDCDrawer} from "@material/drawer";
const drawer = MDCDrawer.attachTo(document.querySelector('.mdc-drawer'));

Icons

We recommend using Material Icons from Google Fonts:

<head>
  <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
</head>

However, you can also use SVG, Font Awesome, or any other icon library you wish.

Making navigation drawers accessible

Focus management

It is recommended to shift focus to the first focusable element in the main content when drawer is closed or one of the destination items is activated. (By default, MDC Drawer restores focus to the menu button which opened it.)

Dismissible drawer

Restore focus to the first focusable element when a list item is activated or after the drawer closes. Do not close the drawer upon item activation, since it should be up to the user when to show/hide the dismissible drawer.

const listEl = document.querySelector('.mdc-drawer .mdc-deprecated-list');
const mainContentEl = document.querySelector('.main-content');

listEl.addEventListener('click', (event) => {
  mainContentEl.querySelector('input, button').focus();
});

document.body.addEventListener('MDCDrawer:closed', () => {
  mainContentEl.querySelector('input, button').focus();
});
Modal drawer

Close the drawer when an item is activated in order to dismiss the modal as soon as the user performs an action. Only restore focus to the first focusable element in the main content after the drawer is closed, since it's being closed automatically.

const listEl = document.querySelector('.mdc-drawer .mdc-deprecated-list');
const mainContentEl = document.querySelector('.main-content');

listEl.addEventListener('click', (event) => {
  drawer.open = false;
});

document.body.addEventListener('MDCDrawer:closed', () => {
  mainContentEl.querySelector('input, button').focus();
});

Types

There are three types of navigation drawers: standard (1), modal (2), and bottom (3).

Standard, modal, and bottom navigation drawers

Standard navigation drawers

Standard navigation drawers allow interaction with both screen content and the drawer at the same time. They can be used on tablet and desktop, but they aren’t suitable for mobile due to limited screen size.

<aside class="mdc-drawer">
  <div class="mdc-drawer__content">
    <nav class="mdc-deprecated-list">
      <a class="mdc-deprecated-list-item mdc-deprecated-list-item--activated" href="#" aria-current="page">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">inbox</i>
        <span class="mdc-deprecated-list-item__text">Inbox</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">send</i>
        <span class="mdc-deprecated-list-item__text">Outgoing</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">drafts</i>
        <span class="mdc-deprecated-list-item__text">Drafts</span>
      </a>
    </nav>
  </div>
</aside>

Modal navigation drawers

Modal navigation drawers block interaction with the rest of an app’s content with a scrim. They are elevated above most of the app’s UI and don’t affect the screen’s layout grid.

<body>
  <aside class="mdc-drawer mdc-drawer--modal">
    <div class="mdc-drawer__content">
      <nav class="mdc-deprecated-list">
        <a class="mdc-deprecated-list-item mdc-deprecated-list-item--activated" href="#" aria-current="page" tabindex="0">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">inbox</i>
          <span class="mdc-deprecated-list-item__text">Inbox</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">send</i>
          <span class="mdc-deprecated-list-item__text">Outgoing</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">drafts</i>
          <span class="mdc-deprecated-list-item__text">Drafts</span>
        </a>
      </nav>
    </div>
  </aside>

  <div class="mdc-drawer-scrim"></div>
  <div>Main Content</div>
</body>

Note: The mdc-drawer-scrim next sibling element is required, to protect the app's UI from interactions while the modal drawer is open.

Bottom navigation drawers

Bottom navigation drawers are modal drawers that are anchored to the bottom of the screen instead of the left or right edge. They are only used with bottom app bars.

MDC Web does not currently support bottom navigation drawers.

Other variants

Drawer with separate list groups

<aside class="mdc-drawer">
  <div class="mdc-drawer__content">
    <nav class="mdc-deprecated-list">
      <a class="mdc-deprecated-list-item mdc-deprecated-list-item--activated" href="#" aria-current="page">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">inbox</i>
        <span class="mdc-deprecated-list-item__text">Inbox</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">star</i>
        <span class="mdc-deprecated-list-item__text">Star</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">send</i>
        <span class="mdc-deprecated-list-item__text">Sent Mail</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">drafts</i>
        <span class="mdc-deprecated-list-item__text">Drafts</span>
      </a>

      <hr class="mdc-deprecated-list-divider">
      <h6 class="mdc-deprecated-list-group__subheader">Labels</h6>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">bookmark</i>
        <span class="mdc-deprecated-list-item__text">Family</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">bookmark</i>
        <span class="mdc-deprecated-list-item__text">Friends</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">bookmark</i>
        <span class="mdc-deprecated-list-item__text">Work</span>
      </a>
    </nav>
  </div>
</aside>

Drawer with header

Drawers can contain a header element which will not scroll with the rest of the drawer content. Things like account switchers and titles should live in the header element.

<aside class="mdc-drawer">
  <div class="mdc-drawer__header">
    <h3 class="mdc-drawer__title">Mail</h3>
    <h6 class="mdc-drawer__subtitle">email@material.io</h6>
  </div>
  <div class="mdc-drawer__content">
    <nav class="mdc-deprecated-list">
      <a class="mdc-deprecated-list-item mdc-deprecated-list-item--activated" href="#" aria-current="page">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">inbox</i>
        <span class="mdc-deprecated-list-item__text">Inbox</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">send</i>
        <span class="mdc-deprecated-list-item__text">Outgoing</span>
      </a>
      <a class="mdc-deprecated-list-item" href="#">
        <span class="mdc-deprecated-list-item__ripple"></span>
        <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">drafts</i>
        <span class="mdc-deprecated-list-item__text">Drafts</span>
      </a>
    </nav>
  </div>
</aside>

Dismissible drawer

Dismissible drawers are by default hidden off screen, and can slide into view. Dismissible drawers should be used when navigation is not common, and the main app content is prioritized.

<body>
  <aside class="mdc-drawer mdc-drawer--dismissible">
    <div class="mdc-drawer__content">
      <nav class="mdc-deprecated-list">
        <a class="mdc-deprecated-list-item mdc-deprecated-list-item--activated" href="#" aria-current="page">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">inbox</i>
          <span class="mdc-deprecated-list-item__text">Inbox</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">send</i>
          <span class="mdc-deprecated-list-item__text">Outgoing</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">drafts</i>
          <span class="mdc-deprecated-list-item__text">Drafts</span>
        </a>
      </nav>
    </div>
  </aside>

  <div class="mdc-drawer-app-content">
    App Content
  </div>
</body>

Note: Apply the mdc-drawer-app-content class to the sibling element after the drawer for the open/close animations to work.

Usage with top app bar
Dismissible drawer: full height drawer

In cases where the drawer occupies the full viewport height, some styles must be applied to get the dismissible drawer and the content below the top app bar to independently scroll and work in all browsers.

In the following example, the mdc-drawer__content and main-content elements should scroll independently of each other. The mdc-drawer--dismissible and mdc-drawer-app-content elements should then sit side-by-side. The markup looks something like this:

<body>
  <aside class="mdc-drawer mdc-drawer--dismissible">
    <div class="mdc-drawer__content">
      <div class="mdc-deprecated-list">
        <a class="mdc-deprecated-list-item mdc-deprecated-list-item--activated" href="#" aria-current="page">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">inbox</i>
          <span class="mdc-deprecated-list-item__text">Inbox</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">send</i>
          <span class="mdc-deprecated-list-item__text">Outgoing</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">drafts</i>
          <span class="mdc-deprecated-list-item__text">Drafts</span>
        </a>
      </div>
    </div>
  </aside>

  <div class="mdc-drawer-app-content">
    <header class="mdc-top-app-bar app-bar" id="app-bar">
      <div class="mdc-top-app-bar__row">
        <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
          <button class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button">menu</button>
          <span class="mdc-top-app-bar__title">Dismissible Drawer</span>
        </section>
      </div>
    </header>

    <main class="main-content" id="main-content">
      <div class="mdc-top-app-bar--fixed-adjust">
        App Content
      </div>
    </main>
  </div>
</body>
Dismissible drawer: below top app bar

In cases where the drawer appears below the top app bar you will want to follow the markup shown below. The mdc-drawer__content and main-content elements will also scroll independently of each other. The mdc-top-app-bar, mdc-drawer and mdc-drawer-app-content will be sibling to each other. The mdc-top-app-bar--fixed-adjust helper class will be applied to mdc-drawer and mdc-drawer-app-content elements to adjust the position with top app bar.

<body>
  <header class="mdc-top-app-bar app-bar" id="app-bar">
    <div class="mdc-top-app-bar__row">
      <section class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start">
        <button class="material-icons mdc-top-app-bar__navigation-icon mdc-icon-button">menu</button>
        <span class="mdc-top-app-bar__title">Dismissible Drawer</span>
      </section>
    </div>
  </header>
  <aside class="mdc-drawer mdc-drawer--dismissible mdc-top-app-bar--fixed-adjust">
    <div class="mdc-drawer__content">
      <div class="mdc-deprecated-list">
        <a class="mdc-deprecated-list-item mdc-deprecated-list-item--activated" href="#" aria-current="page">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">inbox</i>
          <span class="mdc-deprecated-list-item__text">Inbox</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">send</i>
          <span class="mdc-deprecated-list-item__text">Outgoing</span>
        </a>
        <a class="mdc-deprecated-list-item" href="#">
          <span class="mdc-deprecated-list-item__ripple"></span>
          <i class="material-icons mdc-deprecated-list-item__graphic" aria-hidden="true">drafts</i>
          <span class="mdc-deprecated-list-item__text">Drafts</span>
        </a>
      </div>
    </div>
  </aside>

  <div class="mdc-drawer-app-content mdc-top-app-bar--fixed-adjust">
    <main class="main-content" id="main-content">
      App Content
    </main>
  </div>
</body>

The CSS to match either case looks like this:

// Note: These styles do not account for any paddings/margins that you may need.

body {
  display: flex;
  height: 100vh;
}

.mdc-drawer-app-content {
  flex: auto;
  overflow: auto;
  position: relative;
}

.main-content {
  overflow: auto;
  height: 100%;
}

.app-bar {
  position: absolute;
}

// Only apply this style if below top app bar.
.mdc-top-app-bar {
  z-index: 7;
}

The JavaScript to toggle the drawer when the navigation button is clicked looks like this:

import {MDCTopAppBar} from "@material/top-app-bar";
const topAppBar = MDCTopAppBar.attachTo(document.getElementById('app-bar'));
topAppBar.setScrollTarget(document.getElementById('main-content'));
topAppBar.listen('MDCTopAppBar:nav', () => {
  drawer.open = !drawer.open;
});

API

CSS classes

ClassDescription
mdc-drawerMandatory.
mdc-drawer__headerNon-scrollable element that exists at the top of the drawer.
mdc-drawer__contentScrollable content area of the drawer.
mdc-drawer__titleTitle text element of the drawer.
mdc-drawer__subtitleSubtitle text element of the drawer.
mdc-drawer--dismissibleDismissible drawer variant class.
mdc-drawer--modalModal drawer variant class.
mdc-drawer--openIf present, indicates that the dismissible drawer is in the open position.
mdc-drawer--openingApplied while the drawer is animating from the closed to the open position.
mdc-drawer--closingApplied while the drawer is animating from the open to the closed position.
mdc-drawer-app-contentMandatory for dismissible variant only. Sibling element that is resized when the drawer opens/closes.
mdc-drawer-scrimMandatory for modal variant only. Used for the overlay on the app content.

Sass mixins

MixinDescription
border-color($color)Sets border color of mdc-drawer surface.
divider-color($color)Sets divider color found between list groups.
fill-color-accessible($color)Sets the fill color to $color, and list item and icon ink colors to an accessible color relative to $color.
surface-fill-color($color)Sets the background color of mdc-drawer.
title-ink-color($color)Sets the ink color of mdc-drawer__title.
subtitle-ink-colorSets drawer subtitle and list subheader ink color.
item-icon-ink-color($color)Sets drawer list item graphic icon ink color.
item-text-ink-color($color)Sets drawer list item text ink color.
item-activated-icon-ink-color($color)Sets activated drawer list item icon ink color.
item-activated-text-ink-color($color)Sets activated drawer list item text ink color.
shape-radius($radius)Sets the rounded shape to drawer with given radius size. $radius can be single radius or list of 2 radius values for trailing-top and trailing-bottom. Automatically flips the radius values in RTL context.
item-shape-radius($radius, $rtl-reflexive)Sets the rounded shape to drawer navigation item with given radius size. Set $rtl-reflexive to true to flip radius values in RTL context, defaults to true.
activated-overlay-color($color)Sets the overlay color of the activated drawer list item.
scrim-fill-color($color)Sets the fill color of mdc-drawer-scrim.
z-index($value)Sets the z index of drawer. Drawer stays on top of top app bar except for clipped variant of drawer.
width($width)Sets the width of the drawer. In the case of the dismissible variant, also sets margin required for mdc-drawer-app-content.

MDCDrawer

Methods
SignatureDescription
emit(evtType: string, evtData: T, shouldBubble?: boolean) => voidFires a cross-browser-compatible custom event from the component root of the given type, with the given data.
listen(evtType: K, handler: SpecificEventListener<K>, options?: AddEventListenerOptions | boolean) => voidWrapper method to add an event listener to the component's root element. This is most useful when listening for custom events.
unlisten(evtType: K, handler: SpecificEventListener<K>, options?: AddEventListenerOptions | boolean) => voidWrapper method to remove an event listener to the component's root element. This is most useful when unlistening for custom events.
Properties
NameTypeDescription
openbooleanToggles the drawer open and closed.
Events
  • MDCDrawer:closed {} Emits when the navigation drawer has closed.
  • MDCDrawer:opened {} Emits when the navigation drawer has opened.

Usage within web frameworks

If you are using a JavaScript framework, such as React or Angular, you can create this component for your framework. Depending on your needs, you can use the Simple Approach: Wrapping MDC Web Vanilla Components, or the Advanced Approach: Using Foundations and Adapters. Please follow the instructions here.

MDCDrawerAdapter

Methods
SignatureDescription
notifyOpen() => voidEmits a custom event "MDCDrawer:opened" denoting the drawer has opened.
addClass(className: string) => voidAdds a class to the root Element.
focusActiveNavigationItem() => voidFocuses the active / selected navigation item.
hasClass(className: string) => booleanReturns true if the root Element contains the given class.
notifyClose() => voidEmits a custom event "MDCDrawer:closed" denoting the drawer has closed.
elementHasClass(element: Element, className: string) => booleanReturns true if the element contains the given class.
releaseFocus() => voidReleases focus trap from root element which was set by trapFocus and restores focus to where it was prior to calling trapFocus.
removeClass(className: string) => voidRemoves a class from the root Element.
restoreFocus() => voidRestores focus to element previously saved with 'saveFocus'.
saveFocus() => voidSaves the focus of currently active element.
trapFocus() => voidTraps focus on root element and focuses the active navigation element.

MDCDismissibleDrawerFoundation

Methods
SignatureDescription
close() => voidCloses the drawer from the open state.
handleKeydown(evt: KeyboardEvent) => voidKeydown handler to close drawer when key is escape.
handleTransitionEnd(evt: TransitionEvent) => voidHandles the transitionend event when the drawer finishes opening/closing.
closed_() => voidExtension point for when drawer finishes close animation.
isClosing() => booleanReturns true if the drawer is animating closed.
isOpen() => booleanReturns true if the drawer is in the open position.
isOpening() => booleanReturns true if the drawer is animating open.
open() => voidOpens the drawer from the closed state.
opened_() => voidExtension point for when drawer finishes open animation.

MDCModalDrawerFoundation

Methods
SignatureDescription
close() => voidCloses the drawer from the open state.
handleKeydown(evt: KeyboardEvent) => voidKeydown handler to close drawer when key is escape.
handleScrimClick() => voidHandles click event on scrim.
handleTransitionEnd(evt: TransitionEvent) => voidHandles the transitionend event when the drawer finishes opening/closing.
closed_() => voidCalled when drawer finishes close animation.
isClosing() => booleanReturns true if the drawer is animating closed.
isOpen() => booleanReturns true if the drawer is in the open position.
isOpening() => booleanReturns true if the drawer is animating open.
open() => voidOpens the drawer from the closed state.
opened_() => voidCalled when drawer finishes open animation.

Keywords

FAQs

Last updated on 28 Apr 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc