diff --git a/docs/en-US/component/dialog.md b/docs/en-US/component/dialog.md
index c4413cedcf..b0fd80a96b 100644
--- a/docs/en-US/component/dialog.md
+++ b/docs/en-US/component/dialog.md
@@ -69,6 +69,14 @@ The content of Dialog is lazily rendered, which means the default slot is not re
:::
+## Align Center dialog
+
+Open dialog from the center of the screen.
+
+:::demo 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.
+
+dialog/align-center
+
## 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.
@@ -116,6 +124,7 @@ When using `modal` = false, please make sure that `append-to-body` was set to **
| before-close | callback before Dialog closes, and it will prevent Dialog from closing | function(done),done is used to close the Dialog | — | — |
| draggable | enable dragging feature for Dialog | boolean | — | false |
| center | whether to align the header and footer in center | boolean | — | false |
+| align-center | whether to align the dialog both horizontally and vertically | boolean | — | false |
| destroy-on-close | Destroy elements in Dialog when closed | boolean | — | false |
## Slots
diff --git a/docs/examples/dialog/align-center.vue b/docs/examples/dialog/align-center.vue
new file mode 100644
index 0000000000..bee4bd2f1d
--- /dev/null
+++ b/docs/examples/dialog/align-center.vue
@@ -0,0 +1,32 @@
+
+ Click to open the Dialog
+
+
+ Open the dialog from the center from the screen
+
+
+
+
+
+
+
diff --git a/packages/components/dialog/src/dialog-content.ts b/packages/components/dialog/src/dialog-content.ts
index dfa7025f8c..4573c21cd4 100644
--- a/packages/components/dialog/src/dialog-content.ts
+++ b/packages/components/dialog/src/dialog-content.ts
@@ -5,6 +5,10 @@ export const dialogContentProps = buildProps({
type: Boolean,
default: false,
},
+ alignCenter: {
+ type: Boolean,
+ default: false,
+ },
closeIcon: {
type: iconPropType,
},
diff --git a/packages/components/dialog/src/dialog-content.vue b/packages/components/dialog/src/dialog-content.vue
index 39a3a1ef97..d9305c4524 100644
--- a/packages/components/dialog/src/dialog-content.vue
+++ b/packages/components/dialog/src/dialog-content.vue
@@ -5,6 +5,7 @@
ns.b(),
ns.is('fullscreen', fullscreen),
ns.is('draggable', draggable),
+ ns.is('align-center', alignCenter),
{ [ns.m('center')]: center },
customClass,
]"
diff --git a/packages/components/dialog/src/dialog.vue b/packages/components/dialog/src/dialog.vue
index 3a9b20490e..adf80d989c 100644
--- a/packages/components/dialog/src/dialog.vue
+++ b/packages/components/dialog/src/dialog.vue
@@ -20,6 +20,7 @@
:aria-labelledby="!title ? titleId : undefined"
:aria-describedby="bodyId"
:class="`${ns.namespace.value}-overlay-dialog`"
+ :style="overlayDialogStyle"
@click="overlayEvent.onClick"
@mousedown="overlayEvent.onMousedown"
@mouseup="overlayEvent.onMouseup"
@@ -37,6 +38,7 @@
ref="dialogContentRef"
:custom-class="customClass"
:center="center"
+ :align-center="alignCenter"
:close-icon="closeIcon"
:draggable="draggable"
:fullscreen="fullscreen"
@@ -105,6 +107,7 @@ const {
titleId,
bodyId,
style,
+ overlayDialogStyle,
rendered,
zIndex,
afterEnter,
diff --git a/packages/components/dialog/src/use-dialog.ts b/packages/components/dialog/src/use-dialog.ts
index 79fa4b67a5..1c100df224 100644
--- a/packages/components/dialog/src/use-dialog.ts
+++ b/packages/components/dialog/src/use-dialog.ts
@@ -56,6 +56,13 @@ export const useDialog = (
return style
})
+ const overlayDialogStyle = computed(() => {
+ if (props.alignCenter) {
+ return { display: 'flex' }
+ }
+ return {}
+ })
+
function afterEnter() {
emit('opened')
}
@@ -201,6 +208,7 @@ export const useDialog = (
bodyId,
closed,
style,
+ overlayDialogStyle,
rendered,
visible,
zIndex,
diff --git a/packages/theme-chalk/src/dialog.scss b/packages/theme-chalk/src/dialog.scss
index 9215638227..2663e37b2e 100644
--- a/packages/theme-chalk/src/dialog.scss
+++ b/packages/theme-chalk/src/dialog.scss
@@ -21,6 +21,10 @@
outline: none !important;
}
+ @include when(align-center) {
+ margin: auto;
+ }
+
@include when(fullscreen) {
@include set-css-var-value('dialog-width', 100%);
@include set-css-var-value('dialog-margin-top', 0);