Skip to content

Dialog

Dialog component enhanced based on Element Plus Dialog.

Informs users while preserving the current page state.

Basic usage

Dialog pops up a dialog box, and it's quite customizable.

Set model-value / v-model attribute with a Boolean, and Dialog shows when it is true. The Dialog has two parts: body and footer, and the latter requires a slot named footer. The optional title attribute (empty by default) is for defining a title. Finally, this example demonstrates how before-close is used.

TIP

before-close only works when user clicks the close icon or the backdrop. If you have buttons that close the Dialog in the footer named slot, you can add what you would do with before-close in the buttons' click event handler.

Customized Content

The content of Dialog can be anything, even a table or a form. This example shows how to use Table and Form with Dialog.

Customized Header

The header slot can be used to customize the area where the title is displayed. In order to maintain accessibility, use the title attribute in addition to using this slot, or use the titleId slot property to specify which element should be read out as the dialog title.

Nested Dialog

If a Dialog is nested in another Dialog, append-to-body is required.

Normally we do not recommend using nested Dialog. If you need multiple Dialogs rendered on the page, you can simply flat them so that they're siblings to each other. If you must nest a Dialog inside another Dialog, set append-to-body of the nested Dialog to true, and it will append to body instead of its parent node, so both Dialogs can be correctly rendered.

Centered content

Dialog's content can be centered.

Setting center to true will center dialog's header and footer horizontally. center only affects Dialog's header and footer. The body of Dialog can be anything, so sometimes it may not look good when centered. You need to write some CSS if you wish to center the body as well.

TIP

The content of Dialog is lazily rendered, which means the default slot is not rendered onto the DOM until it is firstly opened. Therefore, if you need to perform a DOM manipulation or access a component using ref, do it in the open event callback.

Align Center dialog

Open dialog from the center of the screen.

Setting align-center to true will center the dialog both horizontally and vertically. The prop top will not work at the same time because the dialog is vertically centered in a flexbox.

Destroy on Close

When this is feature is enabled, the content under default slot will be destroyed with a v-if directive. Enable this when you have perf concerns.

Note that by enabling this feature, the content will not be rendered before transition.beforeEnter dispatched, there will only be overlay header(if any) footer(if any).

Draggable Dialog

Try to drag the header part.

Set draggable to true to drag. Set overflow to true can drag overflow the viewport.

TIP

When using modal = false, please make sure that append-to-body was set to true, because Dialog was positioned by position: relative, when modal gets removed, Dialog will position itself based on the current position in the DOM, instead of Document.Body, thus the style will be messed up.

Fullscreen

Set the fullscreen attribute to open fullscreen dialog.

TIP

If fullscreen is true, width top draggable attributes don't work.

Setting modal to false will hide modal (overlay) of dialog.

modal-penetrable attribute is added, which can be penetrable.

Custom Animation

Customize dialog animation through the transition attribute, which accepts either:

  • ​Transition name​​ (string)

  • ​​Vue transition configuration​​ (object)

Examples include scale, slide, fade, bounce animations and object-based configurations with custom event handlers.

TIP

Animation classes are dynamically generated based on the transition name. For granular control over animation behavior, you may explicitly define these classes. Refer to custom-transition-classes for details.

Events

Open developer console (ctrl + shift + J), to see order of events.

Dialog API

Dialog Attributes

Element Plus Dialog Attributes
NameDescriptionTypeDefault
model-value / v-modelvisibility of Dialogbooleanfalse
titletitle of Dialog. Can also be passed with a named slot (see the following table)string''
widthwidth of Dialog, default is 50%string / number''
fullscreenwhether the Dialog takes up full screenbooleanfalse
topvalue for margin-top of Dialog CSS, default is 15vhstring''
modalwhether a mask is displayedbooleantrue
modal-penetrablewhether the mask is penetrable. The modal attribute must be false.booleanfalse
modal-classcustom class names for maskstring
header-classcustom class names for header wrapperstring
body-classcustom class names for body wrapperstring
footer-classcustom class names for footer wrapperstring
append-to-bodywhether to append Dialog itself to body. A nested Dialog should have this attribute set to truebooleanfalse
append-towhich element the Dialog appends to. Will override append-to-bodyCSSSelector / HTMLElementbody
lock-scrollwhether scroll of body is disabled while Dialog is displayedbooleantrue
open-delaythe Time(milliseconds) before opennumber0
close-delaythe Time(milliseconds) before closenumber0
close-on-click-modalwhether the Dialog can be closed by clicking the maskbooleantrue
close-on-press-escapewhether the Dialog can be closed by pressing ESCbooleantrue
show-closewhether to show a close buttonbooleantrue
before-closecallback before Dialog closes, and it will prevent Dialog from closing, use done to close the dialogFunction
draggableenable dragging feature for Dialogbooleanfalse
overflowdraggable Dialog can overflow the viewportbooleanfalse
centerwhether to align the header and footer in centerbooleanfalse
align-centerwhether to align the dialog both horizontally and verticallybooleanfalse
destroy-on-closedestroy elements in Dialog when closedbooleanfalse
close-iconcustom close icon, default is Closestring / Component
z-indexsame as z-index in native CSS, z-order of dialognumber
header-aria-levelheader's aria-level attributestring2
transitioncustom transition configuration for dialog animation. Can be a string (transition name) or an object with Vue transition propsstring / objectdialog-fade

Dialog Slots

Element Plus Dialog Slots
NameDescription
defaultdefault content of Dialog
headercontent of the Dialog header; Replacing this removes the title, but does not remove the close button.
footercontent of the Dialog footer

Dialog Events

Element Plus Dialog Events
NameDescriptionType
opentriggers when the Dialog opensFunction
openedtriggers when the Dialog opening animation endsFunction
closetriggers when the Dialog closesFunction
closedtriggers when the Dialog closing animation endsFunction
open-auto-focustriggers after Dialog opens and content focusedFunction
close-auto-focustriggers after Dialog closed and content focusedFunction

Dialog Exposes

Element Plus Dialog Events
NameDescriptionType
resetPositionreset positionFunction
handleCloseclose dialogFunction

FAQ

Using dialog in SFC, the scope style does not take effect

Typical issue: #10515

PS: Since the dialog is rendered using Teleport, the style of the root node is recommended to be written globally.

When the dialog is displayed and hidden, there is a situation where the page elements are displaced back and forth

Typical issue: #10481

PS: It is recommended to place the scroll area inside a vue mounted node, e.g. <div id="app" />, and use the overflow: hidden style for the body.

Released under the MIT License.