Skip to content

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 abigail-0111 committed Dec 21, 2021
1 parent 5c4767f commit d0a0788
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 @@ -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();
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 d0a0788

Please sign in to comment.