Fix drawer destroy (#20715)

* Drawer: fix destroyOnClose bug
pull/21052/head
zj9495 2021-06-07 15:33:46 +08:00 committed by GitHub
parent 4ed7ac6719
commit e1990a70d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -136,7 +136,12 @@ export default {
}
this.prevActiveElement = document.activeElement;
} else {
if (!this.closed) this.$emit('close');
if (!this.closed) {
this.$emit('close');
if (this.destroyOnClose === true) {
this.rendered = false;
}
}
this.$nextTick(() => {
if (this.prevActiveElement) {
this.prevActiveElement.focus();

View File

@ -132,6 +132,30 @@ describe('Drawer', () => {
expect(vm.$el.querySelector('.el-drawer__body')).not.to.exist;
});
it('should destroy every child by visible change when destroy-on-close flag is true', async() => {
vm = createVue({
template: `
<el-drawer :title='title' :visible='visible' :append-to-body='true' :destroy-on-close='true' ref='drawer'>
<span>${content}</span>
</el-drawer>
`,
data() {
return {
title,
visible: true
};
}
});
await waitImmediate();
expect(vm.$el.querySelector('.el-drawer__body span').textContent).to.equal(
content
);
vm.visible = false;
await wait(400);
expect(vm.$el.querySelector('.el-drawer__body')).not.to.exist;
});
it('should close dialog by clicking the close button', async() => {
vm = createVue({
template: `