menuMDUIDocs
color_lens
The new mdui 2 based on Material Design 3 and Web Components is now available. Check out the mdui 2 documentation.

Navigation Drawer

Navigation drawers in mdui can slide out from the left or right side of the page. A page can have multiple navigation drawers.

The behavior of navigation drawers varies slightly on mobile, tablet, and desktop devices. You can observe the changes in the left navigation drawer on this page by adjusting the browser width:

  1. Height
    • On mobile and tablet devices, the navigation drawer height is always 100%.
    • On desktop devices, navigation drawers do not cover the app bar by default and are positioned one app bar height below the top of the page. Adding the class .mdui-drawer-full-height makes the navigation drawer full-height, which may cause it to cover the app bar. You can add .mdui-appbar-inset to the app bar to prevent it from being covered by the navigation drawer.
  2. Background Color and Shadow
    • On mobile and tablet devices, navigation drawers have a white background and a shadow by default.
    • On desktop devices, navigation drawers have a transparent background and no shadow by default. Adding the class .mdui-color-[color] allows you to set the background color and add a shadow.
  3. Visibility
    • On mobile and tablet devices, navigation drawers are hidden by default.
    • On desktop devices, navigation drawers are visible by default.
    • Adding the class .mdui-drawer-open makes the navigation drawer always visible by default; adding .mdui-drawer-close makes it always hidden by default.
  4. Overlay
    • On mobile and tablet devices, an overlay is always displayed when the navigation drawer is opened.
    • On desktop devices, an overlay is not displayed by default when the navigation drawer is opened. Setting the overlay parameter to true shows the overlay when opened. If it is set to show an overlay, you should add the .mdui-drawer-close class to ensure the navigation drawer is hidden by default.

Usage

  1. (If the component is dynamically generated, mdui.mutation() needs to be called for initialization)
  2. Call via JavaScript

Usage

HTML Structure

<!-- The mdui-drawer-body-left class adds padding-left to the body; add this class whenever there is a navigation drawer on the left that is open by default. -->
<!-- The mdui-drawer-body-right class adds padding-right to the body; add this class whenever there is a navigation drawer on the right that is open by default. -->
<body class="mdui-drawer-body-left mdui-drawer-body-right">

  <!-- Default navigation drawer on the left -->
  <div class="mdui-drawer">
    ... drawer content ...
  </div>

  <!-- To position the navigation drawer on the right, add the class mdui-drawer-right -->
  <div class="mdui-drawer mdui-drawer-right">
    ... drawer content ...
  </div>

</body>

Call via Attributes

This method does not require writing JavaScript code. Simply add the mdui-drawer="options" attribute to a trigger element (e.g., a button). When calling via custom attributes, an additional target parameter is needed to specify the controlled navigation drawer, where the value is the CSS selector of the navigation drawer.

<body class="mdui-drawer-body-right">

  <button class="mdui-btn" mdui-drawer="{target: '#left-drawer'}">open left drawer</button>

  <div class="mdui-drawer" id="left-drawer">
    ... left drawer content ...
    <button class="mdui-btn" mdui-drawer-close>close</button>
  </div>

</body>

Attributes can be added to elements within the navigation drawer to bind events, which are also applicable when using the JavaScript call method.

AttributeDescription
mdui-drawer-closeClicking this element triggers the close.mdui.drawer event and closes the navigation drawer.

Call via JavaScript

// selector is the CSS selector or DOM element of the navigation drawer
// options are configuration parameters, see the parameter list below
var inst = new mdui.Drawer(selector, options);
Run

Param

Param NameTypeDefaultDescription
overlaybooleanfalseWhether to display an overlay when opening the navigation drawer. This parameter only applies to medium screens and above; an overlay is always shown on extra-small and small screens.
swipebooleanfalseWhether to enable swipe gestures.

Method

Method NameDescription
openShow the navigation drawer.
closeHide the navigation drawer.
toggleToggle the visibility of the navigation drawer.
getStateReturns the current state of the navigation drawer (one of: opening, opened, closing, closed).

Event

Event NameDescriptionTargetParams
open.mdui.drawerTriggered when the navigation drawer starts its opening animation.<div class="mdui-drawer"></div>event._detail.inst: Instance
opened.mdui.drawerTriggered when the navigation drawer completes its opening animation.
close.mdui.drawerTriggered when the navigation drawer starts its closing animation.
closed.mdui.drawerTriggered when the navigation drawer completes its closing animation.

CSS Classes

Class NameDescription
.mdui-drawerDefines a navigation drawer.
.mdui-drawer-rightA navigation drawer on the right side of the page.
.mdui-drawer-full-heightMakes the navigation drawer full-height.
.mdui-drawer-openMakes the navigation drawer visible by default.
.mdui-drawer-closeMakes the navigation drawer hidden by default.
.mdui-drawer-body-leftAdds padding-left to body.
.mdui-drawer-body-rightAdds padding-right to body.