Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Fix drawer destroy (ElemeFE#20715)
Browse files Browse the repository at this point in the history
* Drawer: fix destroyOnClose bug
  • Loading branch information
zj9495 authored and CarterLi committed Nov 19, 2021
1 parent 69a4a59 commit 00d39e7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/drawer/src/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ export default {
});
}
} else {
if (!this.closed) this.$emit('close');
if (!this.closed) {
this.$emit('close');
if (this.destroyOnClose === true) {
this.rendered = false;
}
}
if (this.prevActiveElement) {
this.$nextTick(() => {
this.prevActiveElement.focus();
Expand Down
24 changes: 24 additions & 0 deletions test/unit/specs/drawer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down

0 comments on commit 00d39e7

Please sign in to comment.