Drawer

import {Drawer} from "@qualcomm-ui/react/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.

<Drawer.Root placement="start">

Controlled State

Drawer visibility can be controlled using the open, onOpenChange and defaultOpen props. These props follow our controlled state pattern.

Custom Container

Use the container prop of the 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 {type ReactElement, useRef} from "react"

import {Button} from "@qualcomm-ui/react/button"
import {Drawer} from "@qualcomm-ui/react/drawer"
import {Portal} from "@qualcomm-ui/react-core/portal"

export default function DrawerCustomContainerDemo(): ReactElement {
  const containerRef = useRef<HTMLDivElement | null>(null)

  return (
    <div className="grid gap-4">
      <Drawer.Root
        closeOnEscape={false}
        closeOnInteractOutside={false}
        preventScroll={false}
        trapFocus={false}
      >
        <div
          ref={containerRef}
          className="border-neutral-03 relative flex h-96 w-[600px] overflow-hidden border p-8"
        >
          <Drawer.Trigger>
            <Button emphasis="primary" variant="fill">
              Open Drawer
            </Button>
          </Drawer.Trigger>
        </div>

        <Portal container={containerRef}>
          <Drawer.Positioner className="absolute z-0 h-full w-full">
            <Drawer.Content>
              <Drawer.Body>
                <Drawer.Heading>Title</Drawer.Heading>
                <Drawer.CloseButton />
                <Drawer.Description>Description</Drawer.Description>
              </Drawer.Body>

              <Drawer.Footer>
                <Drawer.CloseTrigger>
                  <Button emphasis="primary" size="sm" variant="fill">
                    Confirm
                  </Button>
                </Drawer.CloseTrigger>
              </Drawer.Footer>
            </Drawer.Content>
          </Drawer.Positioner>
        </Portal>
      </Drawer.Root>
    </div>
  )
}

Shortcuts

<Drawer.FloatingPortal>

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

<Portal {...props}>
  <Drawer.Backdrop {...backdropProps} />
  <Drawer.Positioner {...positionerProps}>
    <Drawer.Content {...contentProps}>{children}</Drawer.Content>
  </Drawer.Positioner>
</Portal>

API

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

<Drawer.Root>

Groups all parts of the drawer. Doesn't render its own HTML element.
PropTypeDefault
React children prop.
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
false
The document's text/writing direction.
'ltr' | 'rtl'
'ltr'
Element to receive focus when the dialog is closed
    () => HTMLElement
    A root node to correctly resolve 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
      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
        
        Function called when the escape key is pressed
          (
          event: KeyboardEvent,
          ) => void
          Function called when the animation ends in the closed state
          VoidFunction
          Function called when the focus is moved outside the component
            (
            event: FocusOutsideEvent,
            ) => void
            Function called when an interaction happens outside the component
              (
              event: InteractOutsideEvent,
              ) => void
              Function invoked when the dialog opens or closes
              • openThe next value of the open state.
              (
              open: boolean,
              ) => void
              Function called when the pointer is pressed down outside the component
                (
                event: PointerDownOutsideEvent,
                ) => void
                Function called when this layer is closed due to a parent layer being closed
                  (
                  event: CustomEvent<{
                  originalIndex: number
                  originalLayer: HTMLElement
                  targetIndex: number
                  targetLayer: HTMLElement
                  }>,
                  ) => void
                  The controlled open state of the dialog
                  boolean
                  Returns 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'
                  
                  Whether the node is present (controlled by the user)
                  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 dialog 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 width, font sizes, and internal spacing.
                  '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
                  
                  Description
                  React children prop.
                  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
                  () => HTMLElement
                  Description
                  Element to receive focus when the dialog is closed
                    Type
                    () =>
                    | Node
                    | ShadowRoot
                    | Document
                    Description
                    A root node to correctly resolve 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
                        (
                        event: KeyboardEvent,
                        ) => void
                        Description
                        Function called when the escape key is pressed
                          Type
                          VoidFunction
                          Description
                          Function called when the animation ends in the closed state
                          Type
                          (
                          event: FocusOutsideEvent,
                          ) => void
                          Description
                          Function called when the focus is moved outside the component
                            Type
                            (
                            event: InteractOutsideEvent,
                            ) => void
                            Description
                            Function called when an interaction happens outside the component
                              Type
                              (
                              open: boolean,
                              ) => void
                              Description
                              Function invoked when the dialog opens or closes
                              • openThe next value of the open state.
                              Type
                              (
                              event: PointerDownOutsideEvent,
                              ) => void
                              Description
                              Function called when the pointer is pressed down outside the component
                                Type
                                (
                                event: CustomEvent<{
                                originalIndex: number
                                originalLayer: HTMLElement
                                targetIndex: number
                                targetLayer: HTMLElement
                                }>,
                                ) => void
                                Description
                                Function called when this layer is closed due to a parent layer being closed
                                  Type
                                  boolean
                                  Description
                                  The controlled open state of the dialog
                                  Type
                                  Array<
                                  () => Element
                                  >
                                  Description
                                  Returns 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
                                  Whether the node is present (controlled by the user)
                                  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 dialog 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 width, font sizes, and internal spacing.
                                  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.

                                  <Drawer.Backdrop>

                                  An overlay displayed beneath the drawer to prevent interaction with the rest of the page. Renders a <div> element by default.
                                  PropType
                                  React children prop.
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  string
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  React children prop.
                                  Type
                                  string
                                  Description
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  Type
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                                  <Drawer.Positioner>

                                  A container that positions the drawer on the screen. Renders a <div> element by default.
                                  PropType
                                  React children prop.
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  string
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  React children prop.
                                  Type
                                  string
                                  Description
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  Type
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                                  <Drawer.Content>

                                  A container for the drawer contents. Renders a <section> element by default.
                                  <Dialog.Root>
                                  <Dialog.Positioner>
                                  <Dialog.Content></Dialog.Content>
                                  </Dialog.Positioner>
                                  </Dialog.Root>
                                  PropType
                                  React children prop.
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  string
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  React children prop.
                                  Type
                                  string
                                  Description
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  Type
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                                  <Drawer.Body>

                                  The main content of the drawer. Container for the heading, description, indicator, and primary content of the dialog. Renders a <div> element by default.
                                  PropType
                                  React children prop.
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  React children prop.
                                  Type
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                                  <Drawer.Heading>

                                  PropType
                                  React children prop.
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  string
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  React children prop.
                                  Type
                                  string
                                  Description
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  Type
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                                  <Drawer.IndicatorIcon>

                                  Renders an icon that indicates the drawer's status. Renders a <span> element by default.
                                  PropType
                                  Lucide-react icon or React Element. If this prop is omitted, a fallback icon will be rendered based on the emphasis prop.
                                  | LucideIcon
                                  | ReactNode
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Type
                                  | LucideIcon
                                  | ReactNode
                                  Description
                                  Lucide-react icon or React Element. If this prop is omitted, a fallback icon will be rendered based on the emphasis prop.
                                  Type
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                                  <Drawer.CloseButton>

                                  A button that closes the drawer. Renders a <button> element by default.
                                  PropTypeDefault
                                  LucideIcon
                                  X
                                  
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  string
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Type
                                  LucideIcon
                                  Description
                                  Type
                                  string
                                  Description
                                  id attribute. If omitted, a unique identifier will be automatically generated for accessibility.
                                  Type
                                  | ReactElement
                                  | ((
                                  props: object,
                                  ) => ReactElement)
                                  Description
                                  Allows you to replace the component's HTML element with a different tag or component. Learn more