Dialog is a container to display content in an overlay window.
import { Dialog } from 'primereact/dialog';
<script src="https://unpkg.com/primereact/core/core.min.js"></script>
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 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>
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 may move the dialog boundaries outside of the viewport. Common solution is defining max-height via contentStyle so longer content displays a scrollbar.
Name | Type | Default | Description |
---|---|---|---|
id | string | null | Unique identifier of the element. |
header | any | null | Title content of the dialog. |
footer | any | null | Footer content of the dialog. |
visible | boolean | false | Specifies the visibility of the dialog. |
position | string | center | Position of the dialog, options are "center", "top", "bottom", "left", "right", "top-left", "top-right", "bottom-left" or "bottom-right". |
modal | boolean | true | Defines if background should be blocked when dialog is displayed. |
resizable | boolean | true | Enables resizing of the content. |
draggable | boolean | true | Enables dragging to change the position using header. |
minX | number | 0 | Minimum value for the left coordinate of dialog in dragging. |
minY | number | 0 | Minimum value for the top coordinate of dialog in dragging. |
keepInViewport | boolean | true | Keeps dialog in the viewport. |
headerStyle | object | null | Style of the header section. |
headerClassName | string | null | Style class of the header section. |
contentStyle | object | null | Style of the content section. |
contentClassName | string | null | Style class of the content section. |
closeOnEscape | boolean | true | Specifies if pressing escape key should hide the dialog. |
dismissableMask | boolean | false | Specifies if clicking the modal background should hide the dialog. |
rtl | boolean | false | When enabled dialog is displayed in RTL direction. |
closable | boolean | true | Adds a close icon to the header to hide the dialog. |
style | string | null | Inline style of the component. |
className | string | null | Style class of the component. |
maskStyle | string | null | Inline style of the mask. |
maskClassName | string | null | Style class of the mask. |
showHeader | boolean | true | Whether to show the header or not. |
appendTo | DOM element | string | document.body | DOM 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. |
baseZIndex | number | 0 | Base zIndex value to use in layering. |
maximizable | boolean | false | Whether the dialog can be displayed full screen. |
blockScroll | boolean | false | Whether background scroll should be blocked when dialog is visible. |
icons | any | null | Custom icons template for the header. |
ariaCloseIconLabel | string | null | Defines a string that labels the close icon. |
focusOnShow | boolean | true | When enabled, first button receives focus on show. |
maximized | boolean | false | When enabled, the dialog is initially displayed full screen. |
breakpoints | object | null | Object literal to define widths per screen size. |
transitionOptions | object | null | The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties. |
Name | Parameters | Description |
---|---|---|
onHide | null | Callback to invoke when dialog is hidden (Required). |
onShow | null | Callback to invoke when dialog is showed. |
onMaximize | event.originalEvent: Browser event event.maximized: Whether to show the dialog or not on fullscreen. | Callback to invoke when toggle maximize icon is clicked. |
onDragStart | event: Browser event | Callback to invoke when dialog dragging is initiated. |
onDrag | event: Browser event | Callback to invoke when dragging dialog. |
onDragEnd | event: Browser event | Callback to invoke when dialog dragging is completed. |
onResizeStart | event: Browser event | Callback to invoke when dialog resizing is initiated. |
onResize | event: Browser event | Callback to invoke while resizing dialog. |
onResizeEnd | event: Browser event | Callback to invoke when dialog resizing is completed. |
onMaskClick | event: Browser event | Callback to invoke when the mask is clicked. |
onClick | event: Browser event | Callback to invoke when dialog is clicked. |
Following is the list of structural style classes, for theming classes visit theming page.
Name | Element |
---|---|
p-dialog | Container element. |
p-dialog-titlebar | Container of header. |
p-dialog-title | Header element. |
p-dialog-titlebar-icon | Icon container inside header. |
p-dialog-titlebar-close | Close icon element. |
p-dialog-content | Content element |
This section is under development. After the necessary tests and improvements are made, it will be shared with the users as soon as possible.
None.
Built-in component themes created by the PrimeReact Theme Designer.
Premium themes are only available exclusively for PrimeReact Theme Designer subscribers and therefore not included in PrimeReact core.
Beautifully crafted premium create-react-app application templates by the PrimeTek design team.