Drawer

import {DrawerModule} from "@qualcomm-ui/angular/drawer"

Overview

The drawer's API is similar to the Dialog component.

Examples

Placement End

The drawer's default placement is end, which maps to the right side of the screen in LTR languages and the left side in RTL languages.

Placement Start

Use placement start to change the placement to the left side of the screen.

<div placement="start" q-drawer-root>

Controlled State

Set the initial visibility using the defaultOpen prop, or use open and openChanged to control the visibility manually. These props follow our controlled state pattern.

Custom Container

Use the container prop of the <q-portal> component to render the drawer in a custom container. You'll need to override the positioner's default styles to position the drawer correctly.

Consider setting closeOnInteractOutside to false to prevent the drawer from closing when interacting outside the drawer.

import {Component} from "@angular/core"

import {ButtonModule} from "@qualcomm-ui/angular/button"
import {DrawerModule} from "@qualcomm-ui/angular/drawer"
import {PortalComponent} from "@qualcomm-ui/angular-core/portal"

@Component({
  imports: [DrawerModule, ButtonModule, PortalComponent],
  selector: "drawer-custom-container-demo",
  template: `
    <div
      closeOnEscape="false"
      closeOnInteractOutside="false"
      preventScroll="false"
      q-drawer-root
      trapFocus="false"
    >
      <div
        #containerRef
        class="border-neutral-03 relative flex h-96 w-[600px] overflow-hidden border p-8"
      >
        <button emphasis="primary" q-button q-drawer-trigger variant="fill">
          Open Drawer
        </button>
      </div>

      <q-portal [container]="containerRef">
        <div class="absolute z-0 h-full w-full" q-drawer-positioner>
          <section q-drawer-content>
            <div q-drawer-body>
              <button q-drawer-close-button></button>
              <h2 q-drawer-heading>Drawer Title</h2>
              <div q-drawer-description>Drawer Description</div>
            </div>

            <div q-drawer-footer>
              <button q-button q-drawer-close-trigger size="sm" variant="fill">
                Close
              </button>
            </div>
          </section>
        </div>
      </q-portal>
    </div>
  `,
})
export class DrawerCustomContainerDemo {}

Shortcuts

<q-drawer-floating-portal>

A helper component that combines the portal, positioner, and content components. This shortcut is equivalent to:

<q-portal>
  <div q-drawer-backdrop></div>
  <div q-drawer-positioner>
    <section q-drawer-content><ng-content /></section>
  </div>
</q-portal>

API

The Drawer shares many of its props and data attributes with the Dialog component.

<q-drawer-root>

The root component that provides context for the drawer and its parts.
PropTypeDefault
Human-readable label for the dialog, used when the dialog title is not rendered
string
Whether to close the dialog when the escape key is pressed
boolean
true
Whether to close the dialog when the outside is clicked
boolean
true
The initial open state of the dialog when rendered. Use when you don't need to control the open state of the dialog.
boolean
The document's text/writing direction.
'ltr' | 'rtl'
"ltr"
The style variant of the drawer's indicator.
| 'info'
| 'success'
| 'warning'
| 'danger'
| 'neutral'
'neutral'
Element to receive focus when the dialog is closed
() => HTMLElement
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
() =>
| Node
| ShadowRoot
| Document
Whether to synchronize the present change immediately or defer it to the next frame.
boolean
false
Element to receive focus when the dialog is opened
() => HTMLElement
When true, the component will not be rendered in the DOM until it becomes visible or active.
boolean
false
Whether to prevent pointer interaction outside the element and hide all content below it
boolean
true
The controlled open state of the dialog
boolean
The persistent elements that:
- should not have pointer-events disabled
- should not trigger the dismiss event
Array<
() => Element
>
The horizontal placement of the drawer within the viewport.
| 'start'
| 'end'
'end'
The controlled presence of the node.
boolean
Whether to prevent scrolling behind the dialog when it's opened
boolean
true
Whether to restore focus to the element that had focus before the dialog was opened
boolean
true
The dialog's role
| 'dialog'
| 'alertdialog'
'dialog'
Defines the scroll behavior of the drawer content when modal content exceeds viewport height.
  • 'inside': The modal and backdrop create an internal scroll area within the modal.
  • 'outside': The modal and backdrop move with the page scroll instead of creating an internal scroll area within the modal.
| 'inside'
| 'outside'
'outside'
The size of the drawer's content area and fonts. A smaller size uses less horizontal space.
'sm' | 'md'
'sm'
Whether to allow the initial presence animation.
boolean
false
Whether to trap focus inside the dialog when it's opened
boolean
true
When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
boolean
false
Function called when the escape key is pressed
KeyboardEvent
Function called when the animation ends in the closed state
void
Function called when the focus is moved outside the component
CustomEvent<{
event?: E
}>
Function called when an interaction happens outside the component
| CustomEvent<{event?: E}>
| CustomEvent<{event?: E}>
Fired when the dialog opens or closes.
boolean
Function called when the pointer is pressed down outside the component
CustomEvent<{
event?: E
}>
Function called when this layer is closed due to a parent layer being closed
CustomEvent<{
originalIndex: number
originalLayer: HTMLElement
targetIndex: number
targetLayer: HTMLElement
}>
Type
string
Description
Human-readable label for the dialog, used when the dialog title is not rendered
Type
boolean
Description
Whether to close the dialog when the escape key is pressed
Type
boolean
Description
Whether to close the dialog when the outside is clicked
Type
boolean
Description
The initial open state of the dialog when rendered. Use when you don't need to control the open state of the dialog.
Type
'ltr' | 'rtl'
Description
The document's text/writing direction.
Type
| 'info'
| 'success'
| 'warning'
| 'danger'
| 'neutral'
Description
The style variant of the drawer's indicator.
Type
() => HTMLElement
Description
Element to receive focus when the dialog is closed
Type
() =>
| Node
| ShadowRoot
| Document
Description
A root node to correctly resolve the Document in custom environments. i.e., Iframes, Electron.
Type
boolean
Description
Whether to synchronize the present change immediately or defer it to the next frame.
Type
() => HTMLElement
Description
Element to receive focus when the dialog is opened
Type
boolean
Description
When true, the component will not be rendered in the DOM until it becomes visible or active.
Type
boolean
Description
Whether to prevent pointer interaction outside the element and hide all content below it
Type
boolean
Description
The controlled open state of the dialog
Type
Array<
() => Element
>
Description
The persistent elements that:
- should not have pointer-events disabled
- should not trigger the dismiss event
Type
| 'start'
| 'end'
Description
The horizontal placement of the drawer within the viewport.
Type
boolean
Description
The controlled presence of the node.
Type
boolean
Description
Whether to prevent scrolling behind the dialog when it's opened
Type
boolean
Description
Whether to restore focus to the element that had focus before the dialog was opened
Type
| 'dialog'
| 'alertdialog'
Description
The dialog's role
Type
| 'inside'
| 'outside'
Description
Defines the scroll behavior of the drawer content when modal content exceeds viewport height.
  • 'inside': The modal and backdrop create an internal scroll area within the modal.
  • 'outside': The modal and backdrop move with the page scroll instead of creating an internal scroll area within the modal.
Type
'sm' | 'md'
Description
The size of the drawer's content area and fonts. A smaller size uses less horizontal space.
Type
boolean
Description
Whether to allow the initial presence animation.
Type
boolean
Description
Whether to trap focus inside the dialog when it's opened
Type
boolean
Description
When true, the component will be completely removed from the DOM when it becomes inactive or hidden, rather than just being hidden with CSS.
Type
KeyboardEvent
Description
Function called when the escape key is pressed
Type
void
Description
Function called when the animation ends in the closed state
Type
CustomEvent<{
event?: E
}>
Description
Function called when the focus is moved outside the component
Type
| CustomEvent<{event?: E}>
| CustomEvent<{event?: E}>
Description
Function called when an interaction happens outside the component
Type
boolean
Description
Fired when the dialog opens or closes.
Type
CustomEvent<{
event?: E
}>
Description
Function called when the pointer is pressed down outside the component
Type
CustomEvent<{
originalIndex: number
originalLayer: HTMLElement
targetIndex: number
targetLayer: HTMLElement
}>
Description
Function called when this layer is closed due to a parent layer being closed

<q-drawer-floating-portal>

A helper component that combines the portal, positioner, and content components.
PropType
Override the element that the portal is attached to.
| HTMLElement
| ElementRef<HTMLElement>
Set this to true to disable portalling behavior, causing the children to be rendered as-is.
boolean
Type
| HTMLElement
| ElementRef<HTMLElement>
Description
Override the element that the portal is attached to.
Type
boolean
Description
Set this to true to disable portalling behavior, causing the children to be rendered as-is.

q-drawer-backdrop

The backdrop that overlays the content behind the drawer.

q-drawer-positioner

A container for the drawer content that handles positioning.
PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.

q-drawer-content

A container for the drawer contents.
PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.

q-drawer-body

The main content of the drawer. Container for the heading, description, indicator, and primary content of the drawer.
PropType
Hides the indicator icon.
boolean
Type
boolean
Description
Hides the indicator icon.

q-drawer-heading

A heading that labels the drawer.
PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.
The footer section of the drawer. Typically contains action buttons.

q-drawer-indicator-icon

An icon that indicates the drawer's status.

q-drawer-close-button

A button that closes the drawer.
PropType
id attribute. If omitted, a unique identifier will be generated for accessibility.
string
Type
string
Description
id attribute. If omitted, a unique identifier will be generated for accessibility.