Dialog

A dialog is a focused, overlay-based container used to present critical information or request user input that requires immediate attention. It appears above the application content, blocks underlying interaction, and guides the user toward a required decision or acknowledgement.

import {Dialog} from "@qualcomm-ui/react/dialog"

Examples

Sizes

The dialog component has two sizes: sm and md. Size governs the width of the dialog, as well as the content's spacing, font size, and padding.

import type {ReactElement} from "react"

import {LoremIpsum} from "@qualcomm-ui/react-core/lorem-ipsum"
import {Button} from "@qualcomm-ui/react/button"
import {Dialog, useQdsDialogContext} from "@qualcomm-ui/react/dialog"

export function DialogSizesDemo(): ReactElement {
  return (
    <div className="flex flex-col gap-4">
      <Dialog.Root size="sm">
        <Dialog.Trigger>
          <Button emphasis="primary" variant="fill">
            Open Dialog (sm)
          </Button>
        </Dialog.Trigger>
        <DialogContent />
      </Dialog.Root>

      <Dialog.Root size="md">
        <Dialog.Trigger>
          <Button emphasis="primary" variant="fill">
            Open Dialog (md)
          </Button>
        </Dialog.Trigger>
        <DialogContent />
      </Dialog.Root>
    </div>
  )
}

function DialogContent() {
  const context = useQdsDialogContext()
  return (
    <Dialog.FloatingPortal>
      <Dialog.Body>
        <Dialog.Heading>Dialog Title ({context.size})</Dialog.Heading>
        <Dialog.CloseButton />
        <Dialog.Description>
          <LoremIpsum />
        </Dialog.Description>
      </Dialog.Body>

      <Dialog.Footer>
        <Dialog.CloseTrigger>
          <Button size="sm" variant="outline">
            Cancel
          </Button>
        </Dialog.CloseTrigger>
        <Dialog.CloseTrigger>
          <Button emphasis="primary" size="sm" variant="fill">
            Confirm
          </Button>
        </Dialog.CloseTrigger>
      </Dialog.Footer>
    </Dialog.FloatingPortal>
  )
}

Indicator Icon

Set an indicator icon by providing the <Dialog.IndicatorIcon /> component within the <Dialog.Body> component. Use the emphasis prop on <Dialog.Root> to change its color.

import type {ReactElement} from "react"

import type {QdsDialogEmphasis} from "@qualcomm-ui/qds-core/dialog"
import {LoremIpsum} from "@qualcomm-ui/react-core/lorem-ipsum"
import {Button} from "@qualcomm-ui/react/button"
import {Dialog} from "@qualcomm-ui/react/dialog"

const emphasis: QdsDialogEmphasis[] = [
  "neutral",
  "info",
  "success",
  "warning",
  "danger",
]

export function DialogIndicatorIconDemo(): ReactElement {
  return (
    <div className="flex flex-col gap-4">
      {emphasis.map((emp) => (
        <Dialog.Root key={emp} emphasis={emp}>
          <Dialog.Trigger>
            <Button size="sm" variant="outline">
              {emp}
            </Button>
          </Dialog.Trigger>
          <DialogContent />
        </Dialog.Root>
      ))}
    </div>
  )
}

function DialogContent() {
  return (
    <Dialog.FloatingPortal>
      <Dialog.Body>
        <Dialog.CloseButton />
        <Dialog.IndicatorIcon />
        <Dialog.Heading>Dialog Title</Dialog.Heading>
        <Dialog.Description>
          <LoremIpsum />
        </Dialog.Description>
      </Dialog.Body>

      <Dialog.Footer>
        <Dialog.CloseTrigger>
          <Button emphasis="primary" size="sm" variant="fill">
            Confirm
          </Button>
        </Dialog.CloseTrigger>
      </Dialog.Footer>
    </Dialog.FloatingPortal>
  )
}

Placement

Use the placement prop to change the placement of the dialog.

import type {ReactElement} from "react"

import type {QdsDialogPlacement} from "@qualcomm-ui/qds-core/dialog"
import {Button} from "@qualcomm-ui/react/button"
import {Dialog} from "@qualcomm-ui/react/dialog"

const placement: QdsDialogPlacement[] = ["top", "center", "bottom"]

export function DialogPlacementDemo(): ReactElement {
  return (
    <div className="flex flex-col gap-4">
      {placement.map((plc) => (
        <Dialog.Root key={plc} placement={plc}>
          <Dialog.Trigger>
            <Button emphasis="neutral" size="sm" variant="outline">
              Open Dialog ({plc})
            </Button>
          </Dialog.Trigger>
          <Dialog.FloatingPortal>
            <Dialog.Body>
              <Dialog.Heading>Dialog Title</Dialog.Heading>
              <Dialog.CloseButton />
              <Dialog.Description>Dialog Description</Dialog.Description>
            </Dialog.Body>

            <Dialog.Footer>
              <Dialog.CloseTrigger>
                <Button emphasis="primary" size="sm" variant="fill">
                  Confirm
                </Button>
              </Dialog.CloseTrigger>
            </Dialog.Footer>
          </Dialog.FloatingPortal>
        </Dialog.Root>
      ))}
    </div>
  )
}

Controlled State

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

import {type ReactElement, useState} from "react"

import {Button} from "@qualcomm-ui/react/button"
import {Dialog} from "@qualcomm-ui/react/dialog"

export function DialogControlledStateDemo(): ReactElement {
  const [open, setOpen] = useState<boolean>(false)

  return (
    <Dialog.Root onOpenChange={setOpen} open={open}>
      <Dialog.Trigger>
        <Button emphasis="primary" variant="fill">
          Open Dialog
        </Button>
      </Dialog.Trigger>
      <Dialog.FloatingPortal>
        <Dialog.Body>
          <Dialog.Heading>Dialog Title</Dialog.Heading>
          <Dialog.CloseButton />
          <Dialog.Description>Dialog Description</Dialog.Description>
        </Dialog.Body>

        <Dialog.Footer>
          <Dialog.CloseTrigger>
            <Button emphasis="primary" size="sm" variant="fill">
              Confirm
            </Button>
          </Dialog.CloseTrigger>
        </Dialog.Footer>
      </Dialog.FloatingPortal>
    </Dialog.Root>
  )
}

Outside Scroll

The default scrollBehavior is outside, which makes the entire page scrollable when modal content exceeds viewport height. The modal and backdrop move with the page scroll instead of creating an internal scroll area within the modal.

import type {ReactElement} from "react"

import {LoremIpsum} from "@qualcomm-ui/react-core/lorem-ipsum"
import {Button} from "@qualcomm-ui/react/button"
import {Dialog} from "@qualcomm-ui/react/dialog"

export function DialogOutsideScrollDemo(): ReactElement {
  return (
    <Dialog.Root>
      <Dialog.Trigger>
        <Button emphasis="primary" variant="fill">
          Open Dialog
        </Button>
      </Dialog.Trigger>
      <Dialog.FloatingPortal>
        <Dialog.Body>
          <Dialog.Heading>Dialog Title</Dialog.Heading>
          <Dialog.CloseButton />
          <Dialog.Description>
            <LoremIpsum numParagraphs={20} />
          </Dialog.Description>
        </Dialog.Body>
        <Dialog.Footer>
          <Dialog.CloseTrigger>
            <Button emphasis="primary" size="sm" variant="fill">
              Confirm
            </Button>
          </Dialog.CloseTrigger>
        </Dialog.Footer>
      </Dialog.FloatingPortal>
    </Dialog.Root>
  )
}

Inside Scroll

Set the scrollBehavior prop to inside to create an internal scroll area within the modal.

import type {ReactElement} from "react"

import {LoremIpsum} from "@qualcomm-ui/react-core/lorem-ipsum"
import {Button} from "@qualcomm-ui/react/button"
import {Dialog} from "@qualcomm-ui/react/dialog"

export function DialogInsideScrollDemo(): ReactElement {
  return (
    <Dialog.Root scrollBehavior="inside">
      <Dialog.Trigger>
        <Button emphasis="primary" variant="fill">
          Open Dialog
        </Button>
      </Dialog.Trigger>
      <Dialog.FloatingPortal>
        <Dialog.Body>
          <Dialog.Heading>Dialog Title</Dialog.Heading>
          <Dialog.CloseButton />
          <Dialog.Description>
            <LoremIpsum numParagraphs={20} />
          </Dialog.Description>
        </Dialog.Body>
        <Dialog.Footer>
          <Dialog.CloseTrigger>
            <Button emphasis="primary" size="sm" variant="fill">
              Confirm
            </Button>
          </Dialog.CloseTrigger>
        </Dialog.Footer>
      </Dialog.FloatingPortal>
    </Dialog.Root>
  )
}

Alert Dialog

Set the role prop to alertdialog to change the dialog component to an alert dialog. This is recommended for situations where the dialog is used to notify users of urgent information that demands their immediate attention.

import type {ReactElement} from "react"

import {Trash2} from "lucide-react"

import {Button} from "@qualcomm-ui/react/button"
import {Dialog} from "@qualcomm-ui/react/dialog"

export function DialogAlertDialogDemo(): ReactElement {
  return (
    <Dialog.Root emphasis="danger" role="alertdialog">
      <Dialog.Trigger>
        <Button emphasis="danger" endIcon={Trash2} variant="outline">
          Delete Account
        </Button>
      </Dialog.Trigger>
      <Dialog.FloatingPortal>
        <Dialog.Body>
          <Dialog.IndicatorIcon />
          <Dialog.Heading>Are you sure?</Dialog.Heading>
          <Dialog.CloseButton />
          <Dialog.Description>
            This action cannot be undone. This will permanently delete your
            account and remove your data from our systems.
          </Dialog.Description>
        </Dialog.Body>

        <Dialog.Footer>
          <Dialog.CloseTrigger>
            <Button emphasis="neutral" size="sm" variant="outline">
              Cancel
            </Button>
          </Dialog.CloseTrigger>

          <Button emphasis="danger" size="sm" variant="fill">
            Confirm
          </Button>
        </Dialog.Footer>
      </Dialog.FloatingPortal>
    </Dialog.Root>
  )
}

Shortcuts

<Dialog.FloatingPortal>

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

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

API

<Dialog.Root>

Groups all parts of the dialog. 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'
The style variant of the dialog's indicator icon.
| 'info'
| 'success'
| 'warning'
| 'danger'
| 'neutral'
'neutral'
Element to receive focus when the dialog is closed
() =>
| HTMLElement
| null
| undefined
A root node to correctly resolve document in custom environments. i.e., Iframes, Electron.
() =>
| ShadowRoot
| Document
| Node
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
| null
| undefined
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)
| undefined
Function called when an interaction happens outside the component
| ((
event: InteractOutsideEvent,
) => void)
| undefined
Function invoked when the dialog opens or closes
(
open: boolean,
) => void
Function called when the pointer is pressed down outside the component
| ((
event: PointerDownOutsideEvent,
) => void)
| undefined
Function called when this layer is closed due to a parent layer being closed
(
event: LayerDismissEvent,
) => 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 | null
>
The vertical placement of the dialog within the viewport.
  • 'top': The dialog is positioned at the top of the viewport.
  • 'center': The dialog is positioned at the center of the viewport.
  • 'bottom': The dialog is positioned at the bottom of the viewport.
| 'top'
| 'center'
| 'bottom'
'top'
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 dialog'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
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
| 'info'
| 'success'
| 'warning'
| 'danger'
| 'neutral'
Description
The style variant of the dialog's indicator icon.
Type
() =>
| HTMLElement
| null
| undefined
Description
Element to receive focus when the dialog is closed
Type
() =>
| ShadowRoot
| Document
| Node
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
| null
| undefined
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)
| undefined
Description
Function called when the focus is moved outside the component
Type
| ((
event: InteractOutsideEvent,
) => void)
| undefined
Description
Function called when an interaction happens outside the component
Type
(
open: boolean,
) => void
Description
Function invoked when the dialog opens or closes
Type
| ((
event: PointerDownOutsideEvent,
) => void)
| undefined
Description
Function called when the pointer is pressed down outside the component
Type
(
event: LayerDismissEvent,
) => 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 | null
>
Description
Returns the persistent elements that:
- should not have pointer-events disabled
- should not trigger the dismiss event
Type
| 'top'
| 'center'
| 'bottom'
Description
The vertical placement of the dialog within the viewport.
  • 'top': The dialog is positioned at the top of the viewport.
  • 'center': The dialog is positioned at the center of the viewport.
  • 'bottom': The dialog is positioned at the bottom of 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 dialog'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.

<Dialog.Backdrop>

An overlay displayed beneath the dialog 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

<Dialog.Positioner>

A container that positions the dialog 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

<Dialog.Content>

A container for the dialog contents. Renders a <section> 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

<Dialog.Body>

The main content of the dialog. 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

<Dialog.Heading>

A heading that labels the dialog. Renders an <h2> 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
Content that appears at the bottom of the dialog, typically reserved for actions. 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

<Dialog.IndicatorIcon>

An icon that indicates the dialog'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
| ReactElement
Allows you to replace the component's HTML element with a different tag or component. Learn more
| ReactElement
| ((
props: object,
) => ReactElement)
Type
| LucideIcon
| ReactElement
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

<Dialog.CloseButton>

A button that closes the dialog. 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
Updated by Ryan Bower