diff --git a/docs/en-US/component/dialog.md b/docs/en-US/component/dialog.md index 5380470af9..93bbf62c0a 100644 --- a/docs/en-US/component/dialog.md +++ b/docs/en-US/component/dialog.md @@ -69,6 +69,16 @@ dialog/destroy-on-close ::: +## Draggable Dialog + +Try to drag the `header` part. + +:::demo Set `draggable` to `true` to drag. + +dialog/draggable-dialog + +::: + :::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. @@ -94,6 +104,7 @@ When using `modal` = false, please make sure that `append-to-body` was set to ** | close-on-press-escape | whether the Dialog can be closed by pressing ESC | boolean | — | true | | show-close | whether to show a close button | boolean | — | true | | 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 | | destroy-on-close | Destroy elements in Dialog when closed | boolean | — | false | diff --git a/docs/en-US/component/message-box.md b/docs/en-US/component/message-box.md index 62951a4d52..14ab917a72 100644 --- a/docs/en-US/component/message-box.md +++ b/docs/en-US/component/message-box.md @@ -89,12 +89,22 @@ message-box/distinguishable-close-cancel Content of MessageBox can be centered. -:::demo Setting `center` to `true` will center the content +:::demo Setting `center` to `true` will center the content. message-box/centered-content ::: +## Draggable + +MessageBox can be draggable. + +:::demo Setting `draggable` to `true` allows user to drag MessageBox. + +message-box/draggable + +::: + ## Global method If Element Plus is fully imported, it will add the following global methods for `app.config.globalProperties`: `$msgbox`, `$alert`, `$confirm` and `$prompt`. So in a Vue instance you can call `MessageBox` like what we did in this page. The parameters are: @@ -147,5 +157,6 @@ The corresponding methods are: `ElMessageBox`, `ElMessageBox.alert`, `ElMessageB | input-validator | validation function for the input. Should returns a boolean or string. If a string is returned, it will be assigned to inputErrorMessage | function | — | — | | input-error-message | error message when validation fails | string | — | Illegal input | | center | whether to align the content in center | boolean | — | false | +| draggable | whether MessageBox is draggable | boolean | — | false | | round-button | whether to use round button | boolean | — | false | | button-size | custom size of confirm and cancel buttons | string | small / default / large | default | diff --git a/docs/examples/dialog/draggable-dialog.vue b/docs/examples/dialog/draggable-dialog.vue new file mode 100644 index 0000000000..1ea7d390cc --- /dev/null +++ b/docs/examples/dialog/draggable-dialog.vue @@ -0,0 +1,23 @@ + + + diff --git a/docs/examples/message-box/draggable.vue b/docs/examples/message-box/draggable.vue new file mode 100644 index 0000000000..a830a3d100 --- /dev/null +++ b/docs/examples/message-box/draggable.vue @@ -0,0 +1,32 @@ + + + diff --git a/packages/components/dialog/__tests__/dialog.spec.ts b/packages/components/dialog/__tests__/dialog.spec.ts index c42ed29e69..57c5bfd18c 100644 --- a/packages/components/dialog/__tests__/dialog.spec.ts +++ b/packages/components/dialog/__tests__/dialog.spec.ts @@ -275,5 +275,22 @@ describe('Dialog.vue', () => { const svg = mount(Delete).find('svg').element expect(closeIcon.element.innerHTML).toBe(svg.innerHTML) }) + + test('should render draggable prop', async () => { + const wrapper = _mount({ + slots: { + default: AXIOM, + }, + props: { + modelValue: true, + draggable: true, + }, + }) + + await nextTick() + await rAF() + await nextTick() + expect(wrapper.find('.is-draggable').exists()).toBe(true) + }) }) }) diff --git a/packages/components/dialog/src/dialog.ts b/packages/components/dialog/src/dialog.ts index fa3fd2f5e0..79a0c960e9 100644 --- a/packages/components/dialog/src/dialog.ts +++ b/packages/components/dialog/src/dialog.ts @@ -39,6 +39,10 @@ export const dialogProps = buildProps({ type: Boolean, default: false, }, + draggable: { + type: Boolean, + default: false, + }, lockScroll: { type: Boolean, default: true, diff --git a/packages/components/dialog/src/dialog.vue b/packages/components/dialog/src/dialog.vue index ba3416f465..c093fa9a6c 100644 --- a/packages/components/dialog/src/dialog.vue +++ b/packages/components/dialog/src/dialog.vue @@ -26,6 +26,7 @@ 'el-dialog', { 'is-fullscreen': fullscreen, + 'is-draggable': draggable, 'el-dialog--center': center, }, customClass, @@ -36,7 +37,7 @@ :style="style" @click.stop="" > -
+
{{ title }} @@ -70,12 +71,12 @@