Dialog
A Dialog is a component that focuses the user's attention exclusively on information via a window that is overlaid on primary content. It is also known as a modal or modal dialog.
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.
Indicator Emphasis
Use the emphasis prop to change the intent of the dialog's indicator icon.
Placement
Use the placement prop to change the placement of the dialog.
Controlled State
Dialog visibility can be controlled using the open, onOpenChange and defaultOpen props. These props follow our controlled state pattern.
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.
Inside Scroll
Set the scrollBehavior prop to inside to create an internal scroll area within the modal.
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.
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>
| Prop | Type | Default |
|---|---|---|
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. | | 'info' | 'neutral' |
Element to receive focus when the dialog is closed | () => HTMLElement | |
A root node to correctly resolve document in custom environments. i.e.,
Iframes, Electron. | () => | |
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 | ( | |
Function called when the animation ends in the closed state | VoidFunction | |
Function called when the focus is moved outside the component | ( | |
Function called when an interaction happens outside the component | ( | |
Function invoked when the dialog opens or closes
| ( | |
Function called when the pointer is pressed down outside the component | ( | |
Function called when this layer is closed due to a parent layer being closed | ( | |
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< | |
The vertical placement of the dialog within the viewport. | | 'top' | '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' | 'dialog' |
Defines the scroll behavior of the dialog content when modal content exceeds
viewport height. | | 'inside' | '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 |
stringbooleanbooleanboolean'ltr' | 'rtl'
| 'info'
| 'success'
| 'warning'
| 'danger'
| 'neutral'
() => HTMLElement
() =>
| Node
| ShadowRoot
| Document
boolean() => HTMLElement
booleanboolean(
event: KeyboardEvent,
) => void
VoidFunction(
event: FocusOutsideEvent,
) => void
(
event: InteractOutsideEvent,
) => void
(
open: boolean,
) => void
- openThe next value of the open state.
(
event: PointerDownOutsideEvent,
) => void
(
event: CustomEvent<{
originalIndex: number
originalLayer: HTMLElement
targetIndex: number
targetLayer: HTMLElement
}>,
) => void
booleanArray<
() => Element
>
- should not have pointer-events disabled
- should not trigger the dismiss event
| 'top'
| 'center'
| 'bottom'
booleanbooleanboolean| 'dialog'
| 'alertdialog'
| 'inside'
| 'outside'
'sm' | 'md'
booleanbooleanboolean<Dialog.Backdrop>
<div> element by default.| Prop | Type |
|---|---|
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 |
string| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__backdrop' |
data-part | 'backdrop' |
data-scope | 'dialog' |
data-state | | 'open' |
hidden | boolean |
className'qui-dialog__backdrop'data-part'backdrop'data-scope'dialog'data-state| 'open'
| 'closed'
hiddenboolean<Dialog.Positioner>
<div> element by
default.| Prop | Type |
|---|---|
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 |
string| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__positioner' |
data-placement | | 'top' |
data-scroll-behavior | | 'inside' |
data-size | 'sm' | 'md' |
className'qui-dialog__positioner'data-placement| 'top'
| 'center'
| 'bottom'
data-scroll-behavior| 'inside'
| 'outside'
data-size'sm' | 'md'
<Dialog.Content>
<section> element by default.<Dialog.Root>
<Dialog.Positioner>
<Dialog.Content></Dialog.Content>
</Dialog.Positioner>
</Dialog.Root>
| Prop | Type |
|---|---|
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 |
string| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__content' |
data-part | 'content' |
data-scope | 'dialog' |
data-scroll-behavior | | 'inside' |
data-size | 'sm' | 'md' |
data-state | | 'open' |
hidden | boolean |
tabIndex | -1 |
className'qui-dialog__content'data-part'content'data-scope'dialog'data-scroll-behavior| 'inside'
| 'outside'
data-size'sm' | 'md'
data-state| 'open'
| 'closed'
hiddenbooleantabIndex-1
<Dialog.Body>
<div> element by
default.| Prop | Type |
|---|---|
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement |
| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__body' |
data-part | 'body' |
data-scope | 'dialog' |
data-size | 'sm' | 'md' |
className'qui-dialog__body'data-part'body'data-scope'dialog'data-size'sm' | 'md'
<Dialog.Heading>
<h2> element by default.<Dialog.Content>
<Dialog.Body>
<Dialog.Heading>Title...</Dialog.Heading>
// ... other
</Dialog.Body>
</Dialog.Content>
| Prop | Type |
|---|---|
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 |
string| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__heading' |
data-part | 'heading' |
data-scope | 'dialog' |
data-size | 'sm' | 'md' |
className'qui-dialog__heading'data-part'heading'data-scope'dialog'data-size'sm' | 'md'
<Dialog.Footer>
<div> element by default.| Prop | Type |
|---|---|
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement |
| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__footer' |
data-part | 'footer' |
data-scope | 'dialog' |
data-size | 'sm' | 'md' |
className'qui-dialog__footer'data-part'footer'data-scope'dialog'data-size'sm' | 'md'
<Dialog.IndicatorIcon>
<span> element by default.| Prop | Type |
|---|---|
| LucideIcon | |
Allows you to replace the component's HTML element with a different tag or component. Learn more | | ReactElement |
| LucideIcon
| ReactNode
| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__indicator-icon' |
data-emphasis | | 'info' |
data-size | 'sm' | 'md' |
className'qui-dialog__indicator-icon'data-emphasis| 'info'
| 'success'
| 'warning'
| 'danger'
| 'neutral'
data-size'sm' | 'md'
<Dialog.CloseButton>
<button> element by default.| Prop | Type | Default |
|---|---|---|
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 |
LucideIconstring| ReactElement
| ((
props: object,
) => ReactElement)
| Attribute / Property | Value |
|---|---|
className | 'qui-dialog__close-button' |
data-part | 'close-trigger' |
data-scope | 'dialog' |
className'qui-dialog__close-button'data-part'close-trigger'data-scope'dialog'