Skip to content

Commit

Permalink
Dialog: add opened event (#12828)
Browse files Browse the repository at this point in the history
* Dialog: add opened event

* Docs: update es dialog doc

* Update dialog.md
  • Loading branch information
ibufu authored Sep 20, 2018
1 parent 098ba46 commit fff4d62
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/docs/en-US/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,6 @@ If the variable bound to `visible` is managed in Vuex store, the `.sync` can not
| Event Name | Description | Parameters |
|---------- |-------- |---------- |
| open | triggers when the Dialog opens ||
| opened | triggers when the Dialog opening animation ends ||
| close | triggers when the Dialog closes ||
| closed | triggers when the Dialog closing animation ends ||
1 change: 1 addition & 0 deletions examples/docs/es/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ Si la variable ligada a `visible` se gestiona en el Vuex store, el `.sync` no pu
| Nombre de Evento | Descripcíon | Parámetros |
| ---------------- | ---------------------------------------- | ---------- |
| open | se activa cuando se abre el cuadro de Diálogo ||
| opened | triggers when the Dialog opening animation ends ||
| close | se dispara cuando el Diálogo se cierra ||
| closed | se activa cuando finaliza la animación de cierre del Diálog ||

1 change: 1 addition & 0 deletions examples/docs/zh-CN/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,6 @@ Dialog 的内容是懒渲染的,即在第一次被打开之前,传入的默
| 事件名称 | 说明 | 回调参数 |
|---------- |-------- |---------- |
| open | Dialog 打开的回调 ||
| opened | Dialog 打开动画结束时的回调 ||
| close | Dialog 关闭的回调 ||
| closed | Dialog 关闭动画结束时的回调 ||
4 changes: 4 additions & 0 deletions packages/dialog/src/component.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<transition
name="dialog-fade"
@after-enter="afterEnter"
@after-leave="afterLeave">
<div class="el-dialog__wrapper" v-show="visible" @click.self="handleWrapperClick">
<div
Expand Down Expand Up @@ -169,6 +170,9 @@
this.broadcast('ElSelectDropdown', 'updatePopper');
this.broadcast('ElDropdownMenu', 'updatePopper');
},
afterEnter() {
this.$emit('opened');
},
afterLeave() {
this.$emit('closed');
}
Expand Down
21 changes: 17 additions & 4 deletions test/unit/specs/dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ describe('Dialog', () => {
<div>
<el-dialog
@open="handleOpen"
@opened="handleOpened"
@close="handleClose"
@closed="handleClosed"
:title="title"
:visible.sync="visible">
<span>这是一段信息</span>
Expand All @@ -170,14 +172,23 @@ describe('Dialog', () => {
this.state = 'open';
},

handleOpened() {
this.animationState = 'opened';
},

handleClose() {
this.state = 'closed';
this.state = 'close';
},

handleClosed() {
this.animationState = 'closed';
}
},

data() {
return {
state: '',
animationState: '',
title: 'dialog test',
visible: false
};
Expand All @@ -186,12 +197,14 @@ describe('Dialog', () => {
vm.visible = true;
setTimeout(() => {
expect(vm.state).to.equal('open');
expect(vm.animationState).to.equal('opened');
vm.visible = false;
setTimeout(() => {
expect(vm.state).to.equal('closed');
expect(vm.state).to.equal('close');
expect(vm.animationState).to.equal('closed');
done();
}, 50);
}, 50);
}, 400);
}, 400);
});
it('click dialog to close', done => {
vm = createVue({
Expand Down

0 comments on commit fff4d62

Please sign in to comment.