[new feature] Popup: add click event

This commit is contained in:
陈嘉涵 2019-04-30 19:10:19 +08:00
parent ef77166246
commit 848786dd6e
5 changed files with 21 additions and 4 deletions

View File

@ -53,6 +53,10 @@
- 新增`Skeleton`骨架屏组件
### Popup
- 新增`click`事件
### Loading
- 新增`default`插槽

View File

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

View File

@ -25,7 +25,7 @@ export default sfc({
}
const { position } = this;
const emit = event => () => this.$emit(event);
const emit = eventName => event => this.$emit(eventName, event);
const transitionName = this.transition || (position ? `van-popup-slide-${position}` : 'van-fade');
return (
@ -34,7 +34,7 @@ export default sfc({
onAfterEnter={emit('opened')}
onAfterLeave={emit('closed')}
>
<div vShow={this.value} class={bem({ [position]: position })}>
<div vShow={this.value} class={bem({ [position]: position })} onClick={emit('click')}>
{this.slots()}
</div>
</transition>

View File

@ -171,10 +171,21 @@ test('close on click modal', () => {
expect(wrapper.vm.value).toBeFalsy();
});
test('oepn & close event', () => {
wrapper = mount(Popup);
test('open & close event', () => {
const wrapper = mount(Popup);
wrapper.vm.value = true;
expect(wrapper.emitted('open')).toBeTruthy();
wrapper.vm.value = false;
expect(wrapper.emitted('close')).toBeTruthy();
});
test('click event', () => {
const wrapper = mount(Popup, {
propsData: {
value: true
}
});
wrapper.trigger('click');
expect(wrapper.emitted('click')).toBeTruthy();
});

View File

@ -54,6 +54,7 @@ export default {
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| click | 点击弹出层时触发 | - |
| open | 打开弹出层时触发 | - |
| opened | 打开弹出层且动画结束后触发 | - |
| close | 关闭弹出层时触发 | - |