Back to Fluentui

Drawer

packages/web-components/src/drawer/README.md

4.40.2-hotfix25.3 KB
Original Source

Drawer

The Drawer component represents a drawer that can be opened and closed, typically used for navigation or additional content.

Design Spec

Link to Drawer Design Spec in Figma: Link

Engineering Spec

The Fluent WC3 Drawer extends FASTElement

Class Drawer

Template

ts
export function drawerTemplate<T extends Drawer>(): ElementViewTemplate<T> {
  return html<T>`
    <dialog
      class="dialog"
      part="dialog"
      role="${x => (x.type === 'modal' ? 'dialog' : void 0)}"
      aria-modal="${x => (x.type === 'modal' ? 'true' : void 0)}"
      aria-describedby="${x => x.ariaDescribedby}"
      aria-labelledby="${x => x.ariaLabelledby}"
      aria-label="${x => x.ariaLabel}"
      size="${x => x.size}"
      position="${x => x.position}"
      type="${x => x.type}"
      @click="${(x, c) => x.clickHandler(c.event as MouseEvent)}"
      @cancel="${(x, c) => x.hide()}"
      ${ref('dialog')}
    >
      <slot></slot>
    </dialog>
  `;
}

Variables

NameTypeDescription
DrawerPositionstart endPositions for Drawer
DrawerSizesmall medium large fullSizes for Drawer
DrawerTypemodal non-modal inlineModal types for Drawer

Attributes

NamePrivacyTypeDescription
typepublicDrawerTypeDetermines whether the drawer should be displayed as a modal, non-modal or inline drawer.
positionpublicDrawerPositionSets the position of the drawer (start/end).
sizepublicDrawerSizeSets the size of the drawer (small/medium/large).
ariaDescribedbypublicstringThe ID of the element that describes the drawer.
ariaLabelledbypublicstringThe ID of the element that labels the drawer.

Events

NameTypeDescription
toggleCustomEventFires after the dialog's open state changes
beforetoggleCustomEventFires before the dialog's open state changes

Methods

NamePrivacyDescription
showpublicShows the drawer.
hidepublicHides the drawer.
emitTogglepublicMethod to emit an event after the dialog's open state changes.
emitBeforeTogglepublicMethod to emit an event before the dialog's open state changes.
clickHandlerpublicHandles click events on the drawer.
keydownHandlerpublicHandles keydown events on the drawer.

Slots

NameDescription
The default slot for the main content

CSS Variables

NameDescription
--drawer-widthUsed to set the width of the drawer

Accessiblity

WAI-ARIA Roles, States, and Properties

NamePrivacyTypeDescription
rolepublicstringSets the role of the dialog element to dialog when modal dialog is rendered.
aria-modalpublicstring or undefinedIndicates if the drawer is modal.
aria-describedbypublicstringThe ID of the element that describes the drawer.
aria-labelledbypublicstringThe ID of the element that labels the drawer.
aria-labelpublicstringProvides an accessible name for the drawer when aria-labelledby is not used.

Fluent Web Component v3 v.s Fluent React 9

Component and Slot Mapping

Fluent UI React 9Fluent Web Components 3
<DrawerOverlay>type="modal"
<DrawerInline>type="inline"
<DrawerBody> <drawer-body>