[new feature] Popup: add open/close event (#2649)

This commit is contained in:
neverland 2019-01-30 19:39:29 +08:00 committed by GitHub
parent 079b582460
commit 466bb3ce1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -48,8 +48,10 @@ export default {
watch: {
value(val) {
const type = val ? 'open' : 'close';
this.inited = this.inited || this.value;
this[val ? 'open' : 'close']();
this[type]();
this.$emit(type);
},
getContainer() {

View File

@ -54,4 +54,6 @@ Use `position` prop to set popup display position
| Event | Description | Arguments |
|------|------|------|
| open | Triggered when open Popup | - |
| close | Triggered when close Popup | - |
| click-overlay | Triggered when click overlay | - |

View File

@ -141,3 +141,11 @@ test('close on click modal', () => {
modal.click();
expect(wrapper.vm.value).toBeFalsy();
});
test('oepn & close event', () => {
wrapper = mount(Popup);
wrapper.vm.value = true;
expect(wrapper.emitted('open')).toBeTruthy();
wrapper.vm.value = false;
expect(wrapper.emitted('close')).toBeTruthy();
});

View File

@ -54,4 +54,6 @@ export default {
| 事件名 | 说明 | 参数 |
|------|------|------|
| open | 打开弹出层时触发 | - |
| close | 关闭弹出层时触发 | - |
| click-overlay | 点击蒙层时触发 | - |