lara-light-indigo

Dialog

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

Basic
Without Modal
Responsive
Maximizable
Position
Import via Module

import { Dialog } from 'primereact/dialog';
 
Import via CDN

<script src="https://unpkg.com/primereact/core/core.min.js"></script>
 
Getting Started

Dialog is used as a container and visibility is managed with visible property where onHide event is required to update the visibility state.


<Button label="Show" icon="pi pi-external-link" onClick={() => onClick('displayBasic')} />

<Dialog header="Header" visible={displayBasic} style={{ width: '50vw' }} footer={renderFooter('displayBasic')} onHide={() => onHide('displayBasic')}>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
    Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
    Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
    cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</Dialog>
 
Header and Footer

Header and Footer sections are defined using properties with the same name that accept simple strings or JSX for custom content. In addition icons property enables adding more icons at the header section.


const footer = (
    <div>
        <Button label="Yes" icon="pi pi-check" onClick={onHide} />
        <Button label="No" icon="pi pi-times" onClick={onHide} />
    </div>
);

const myIcon = (
    <button className="p-dialog-titlebar-icon p-link">
        <span className="pi pi-search"></span>
    </button>
)

<Dialog header="Header Text" footer={footer} icons={myIcon} visible={visible} style={{width: '50vw'}} modal onHide={onHide}>
    Content
</Dialog>
 
Responsive

Dialog width can be adjusted per screen size with the breakpoints option. In example below, default width is set to 50vw and below 961px, width would be 75vw and finally below 641px width becomes 100%. The value of breakpoints should be an object literal whose keys are the maximum screen sizes and values are the widths per screen.


<Dialog visible={visible} onHide={onHide} breakpoints={{'960px': '75vw', '640px': '100vw'}} style={{width: '50vw'}}>
    Content
</Dialog>
 
Dynamic Content

Dynamic content may move the dialog boundaries outside of the viewport. Common solution is defining max-height via contentStyle so longer content displays a scrollbar.

Properties
NameTypeDefaultDescription
idstringnullUnique identifier of the element.
headeranynullTitle content of the dialog.
footeranynullFooter content of the dialog.
visiblebooleanfalseSpecifies the visibility of the dialog.
positionstringcenterPosition of the dialog, options are "center", "top", "bottom", "left", "right", "top-left", "top-right", "bottom-left" or "bottom-right".
modalbooleantrueDefines if background should be blocked when dialog is displayed.
resizablebooleantrueEnables resizing of the content.
draggablebooleantrueEnables dragging to change the position using header.
minXnumber0Minimum value for the left coordinate of dialog in dragging.
minYnumber0Minimum value for the top coordinate of dialog in dragging.
keepInViewportbooleantrueKeeps dialog in the viewport.
headerStyleobjectnullStyle of the header section.
headerClassNamestringnullStyle class of the header section.
contentStyleobjectnullStyle of the content section.
contentClassNamestringnullStyle class of the content section.
closeOnEscapebooleantrueSpecifies if pressing escape key should hide the dialog.
dismissableMaskbooleanfalseSpecifies if clicking the modal background should hide the dialog.
rtlbooleanfalseWhen enabled dialog is displayed in RTL direction.
closablebooleantrueAdds a close icon to the header to hide the dialog.
stylestringnullInline style of the component.
classNamestringnullStyle class of the component.
maskStylestringnullInline style of the mask.
maskClassNamestringnullStyle class of the mask.
showHeaderbooleantrueWhether to show the header or not.
appendToDOM element | stringdocument.bodyDOM element instance where the overlay panel should be mounted. Valid values are any DOM Element and 'self'. The self value is used to render a component where it is located.
baseZIndexnumber0Base zIndex value to use in layering.
maximizablebooleanfalseWhether the dialog can be displayed full screen.
blockScrollbooleanfalseWhether background scroll should be blocked when dialog is visible.
iconsanynullCustom icons template for the header.
ariaCloseIconLabelstringnullDefines a string that labels the close icon.
focusOnShowbooleantrueWhen enabled, first button receives focus on show.
maximizedbooleanfalseWhen enabled, the dialog is initially displayed full screen.
breakpointsobjectnullObject literal to define widths per screen size.
transitionOptionsobjectnullThe properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
Events
NameParametersDescription
onHidenullCallback to invoke when dialog is hidden (Required).
onShownullCallback to invoke when dialog is showed.
onMaximizeevent.originalEvent: Browser event
event.maximized: Whether to show the dialog or not on fullscreen.
Callback to invoke when toggle maximize icon is clicked.
onDragStartevent: Browser eventCallback to invoke when dialog dragging is initiated.
onDragevent: Browser eventCallback to invoke when dragging dialog.
onDragEndevent: Browser eventCallback to invoke when dialog dragging is completed.
onResizeStartevent: Browser eventCallback to invoke when dialog resizing is initiated.
onResizeevent: Browser eventCallback to invoke while resizing dialog.
onResizeEndevent: Browser eventCallback to invoke when dialog resizing is completed.
onMaskClickevent: Browser eventCallback to invoke when the mask is clicked.
onClickevent: Browser eventCallback to invoke when dialog is clicked.
Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
p-dialogContainer element.
p-dialog-titlebarContainer of header.
p-dialog-titleHeader element.
p-dialog-titlebar-iconIcon container inside header.
p-dialog-titlebar-closeClose icon element.
p-dialog-contentContent element
Accessibility

This section is under development. After the necessary tests and improvements are made, it will be shared with the users as soon as possible.

Dependencies

None.

Component Scale

Input Style

Ripple Effect

Free Themes

Built-in component themes created by the PrimeReact Theme Designer.

Bootstrap
Blue
Purple
Blue
Purple
Material Design
Indigo
Deep Purple
Indigo
Deep Purple
Material Design Compact
Indigo
Deep Purple
Indigo
Deep Purple
Tailwind
Tailwind Light
Fluent UI
Blue
PrimeOne Design - 2022 NEW
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
Lara Indigo
Lara Blue
Lara Purple
Lara Teal
PrimeOne Design - 2021
Saga Blue
Saga Green
Saga Orange
Saga Purple
Vela Blue
Vela Green
Vela Orange
Vela Purple
Arya Blue
Arya Green
Arya Orange
Arya Purple
Premium Themes

Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.

Soho Light
Soho Dark
Viva Light
Viva Dark
Mira
Nano

Legacy Free Themes

Nova
Nova Alt
Nova Accent
Luna Blue
Luna Green
Luna Amber
Luna Pink
Rhea

Premium Create-React-App Templates

Beautifully crafted premium create-react-app application templates by the PrimeTek design team.

Sakai
Atlantis
Freya
Ultima
Diamond
Sapphire
Serenity
Babylon
Avalon
Apollo
Roma