Introducing PrimeReact v11-alpha 🎉Discover Now

Dialog

Dialog is a container to display content in an overlay window.

preview

Installation#

npx shadcn@latest add @primereact/dialog

Usage#

import { Dialog, DialogBackdrop, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogHeaderActions, DialogMaximizable, DialogPopup, DialogPortal, DialogPositioner, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
<Dialog>
    <DialogTrigger />
    <DialogPortal>
        <DialogBackdrop />
        <DialogPositioner>
            <DialogPopup>
                <DialogHeader>
                    <DialogTitle />
                    <DialogHeaderActions>
                        <DialogMaximizable />
                        <DialogClose />
                    </DialogHeaderActions>
                </DialogHeader>
                <DialogContent />
                <DialogFooter />
            </DialogPopup>
        </DialogPositioner>
    </DialogPortal>
</Dialog>

Examples#

Basic#

basic-demo

Draggable#

A dialog can be repositioned by dragging its header when the draggable prop is enabled.

draggable-demo

Position#

The position of the dialog can be customized with the position property. The available values are top, top-left, top-right, bottom, bottom-left, bottom-right, left, right, and center.

position-demo

Maximizable#

A dialog can be maximized by clicking the Dialog.Maximizable button.

maximizable-demo

Full Screen#

The fullScreen prop opens the dialog in maximized mode. Without a Dialog.Maximizable button, the dialog remains full screen until closed.

fullscreen-demo

Without Modal#

Mask layer behind the Dialog is configured with the modal property. By default, no modal layer is added.

without-modal-demo

Confirmation#

A common pattern for confirmation dialogs with warning messages and action buttons.

confirmation-demo

Inside Scroll#

When scrollBehavior is set to inside, the dialog content area scrolls while the header and footer remain fixed.

inside-scroll-demo

Outside Scroll#

When scrollBehavior is set to outside, the entire dialog scrolls within the positioner, allowing the full dialog to move as a single unit.

outside-scroll-demo

Responsive#

Dialog width adapts to different screen sizes using responsive CSS classes on the DialogPopup.

responsive-demo

Accessibility#

Screen Reader#

Dialog component uses dialog role along with aria-labelledby referring to the header element however any attribute is passed to the root element so aria-labelledby can be used to override this default behavior. In addition aria-modal is added since focus is kept within the popup.

Trigger element also has aria-expanded and aria-controls to be handled explicitly.

Overlay Keyboard Support#

KeyFunction
tabMoves focus to the next the focusable element within the dialog if modal is true. Otherwise, the focusable element in the page tab sequence.
shift + tabMoves focus to the previous the focusable element within the dialog if modal is true. Otherwise, the focusable element in the page tab sequence.
escapeCloses the dialog if closeOnEscape is true.

Close Button Keyboard Support#

KeyFunction
enterCloses the dialog.
spaceCloses the dialog.