Skip to content

Commit d238c76

Browse files
ziyoungiamkun
authored andcommitted
Dialog: add destroyOnClose attribute (ElemeFE#16455)
* Dialog: add destroyOnClose attribute * update
1 parent 11bfd55 commit d238c76

File tree

7 files changed

+51
-6
lines changed

7 files changed

+51
-6
lines changed

examples/docs/en-US/dialog.md

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ If the variable bound to `visible` is managed in Vuex store, the `.sync` can not
221221
| show-close | whether to show a close button | boolean || true |
222222
| before-close | callback before Dialog closes, and it will prevent Dialog from closing | function(done),done is used to close the Dialog |||
223223
| center | whether to align the header and footer in center | boolean || false |
224+
| destroy-on-close | Destroy elements in Dialog when closed | boolean || false |
224225

225226
### Slot
226227

examples/docs/es/dialog.md

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ Si la variable ligada a `visible` se gestiona en el Vuex store, el `.sync` no pu
229229
| show-close | si mostrar un botón de cerrar | boolean || true |
230230
| before-close | una devolución de llamada antes de que se cierre el cuadro de diálogo, y evitar cerrar el cuadro de diálogo | función(done) `done`se usa para cerrar el diálog |||
231231
| center | si alinear el encabezado y el pie de página en el centro | boolean || false |
232+
| destroy-on-close | Destroy elements in Dialog when closed | boolean || false |
232233

233234
### Slots
234235

examples/docs/fr-FR/dialog.md

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ Si la variable liée à `visible` est gérée dans Vuex, le modificateur `.sync`
224224
| show-close | Si le bouton de fermeture doit apparaître. | boolean || true |
225225
| before-close | Callback avant la fermeture du Dialog. | function(done),done est utilisé pour fermer le Dialog. |||
226226
| center | Si le header et le footer doivent être centrés. | boolean || false |
227+
| destroy-on-close | Destroy elements in Dialog when closed | boolean || false |
227228

228229
### Slot
229230

examples/docs/zh-CN/dialog.md

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Dialog 的内容是懒渲染的,即在第一次被打开之前,传入的默
219219
| show-close | 是否显示关闭按钮 | boolean || true |
220220
| before-close | 关闭前的回调,会暂停 Dialog 的关闭 | function(done),done 用于关闭 Dialog |||
221221
| center | 是否对头部和底部采用居中布局 | boolean || false |
222+
| destroy-on-close | 关闭时销毁 Dialog 中的元素 | boolean || false |
222223

223224
### Slot
224225
| name | 说明 |

packages/dialog/src/component.vue

+16-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
name="dialog-fade"
44
@after-enter="afterEnter"
55
@after-leave="afterLeave">
6-
<div class="el-dialog__wrapper" v-show="visible" @click.self="handleWrapperClick">
6+
<div
7+
v-show="visible"
8+
class="el-dialog__wrapper"
9+
@click.self="handleWrapperClick">
710
<div
811
role="dialog"
12+
:key="key"
913
aria-modal="true"
1014
:aria-label="title || 'dialog'"
11-
class="el-dialog"
12-
:class="[{ 'is-fullscreen': fullscreen, 'el-dialog--center': center }, customClass]"
15+
:class="['el-dialog', { 'is-fullscreen': fullscreen, 'el-dialog--center': center }, customClass]"
1316
ref="dialog"
1417
:style="style">
1518
<div class="el-dialog__header">
@@ -102,12 +105,15 @@
102105
center: {
103106
type: Boolean,
104107
default: false
105-
}
108+
},
109+
110+
destroyOnClose: Boolean
106111
},
107112
108113
data() {
109114
return {
110-
closed: false
115+
closed: false,
116+
key: 0
111117
};
112118
},
113119
@@ -126,6 +132,11 @@
126132
} else {
127133
this.$el.removeEventListener('scroll', this.updatePopper);
128134
if (!this.closed) this.$emit('close');
135+
if (this.destroyOnClose) {
136+
this.$nextTick(() => {
137+
this.key++;
138+
});
139+
}
129140
}
130141
}
131142
},

test/unit/specs/dialog.spec.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createVue, destroyVM } from '../util';
1+
import { createVue, destroyVM, waitImmediate } from '../util';
22

33
describe('Dialog', () => {
44
let vm;
@@ -289,4 +289,31 @@ describe('Dialog', () => {
289289
}, 500);
290290
}, 10);
291291
});
292+
293+
it('destroyOnClose', async() => {
294+
vm = createVue({
295+
template: `
296+
<div>
297+
<el-dialog :title="title" :visible.sync="visible" destroy-on-close>
298+
<input />
299+
</el-dialog>
300+
</div>
301+
`,
302+
303+
data() {
304+
return {
305+
title: 'dialog test',
306+
visible: true
307+
};
308+
}
309+
}, true);
310+
const dialog = vm.$children[0];
311+
await waitImmediate();
312+
dialog.$el.querySelector('input').value = '123';
313+
dialog.$el.click();
314+
await waitImmediate();
315+
vm.visible = true;
316+
await waitImmediate();
317+
expect(dialog.$el.querySelector('input').value).to.be.equal('');
318+
});
292319
});

types/dialog.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@ export declare class ElDialog extends ElementUIComponent {
5555
/** Whether to align the header and footer in center */
5656
center: boolean
5757

58+
/** Whether to destroy elements in Dialog when closed */
59+
destroyOnClose: boolean
60+
5861
$slots: DialogSlots
5962
}

0 commit comments

Comments
 (0)