feat(Popover): add click-overlay event (#8050)

This commit is contained in:
neverland 2021-01-31 18:43:18 +08:00 committed by GitHub
parent d27626ada2
commit 63227201ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 14 deletions

View File

@ -227,13 +227,14 @@ export default {
### Events
| Event | Description | Arguments |
| ------ | --------------------------------- | ------------------------------- |
| Event | Description | Arguments |
| --- | --- | --- |
| select | Emitted when an action is clicked | _action: Action, index: number_ |
| open | Emitted when opening Popover | - |
| close | Emitted when closing Popover | - |
| opened | Emitted when Popover is opened | - |
| closed | Emitted when Popover is closed | - |
| open | Emitted when opening Popover | - |
| close | Emitted when closing Popover | - |
| opened | Emitted when Popover is opened | - |
| closed | Emitted when Popover is closed | - |
| click-overlay | Emitted when overlay is clicked | - |
### Slots

View File

@ -243,13 +243,14 @@ export default {
### Events
| 事件名 | 说明 | 回调参数 |
| ------ | ------------------------ | ------------------------------- |
| select | 点击选项时触发 | _action: Action, index: number_ |
| open | 打开菜单时触发 | - |
| close | 关闭菜单时触发 | - |
| opened | 打开菜单且动画结束后触发 | - |
| closed | 关闭菜单且动画结束后触发 | - |
| 事件名 | 说明 | 回调参数 |
| ------------- | ------------------------ | ------------------------------- |
| select | 点击选项时触发 | _action: Action, index: number_ |
| open | 打开菜单时触发 | - |
| close | 关闭菜单时触发 | - |
| opened | 打开菜单且动画结束后触发 | - |
| closed | 关闭菜单且动画结束后触发 | - |
| click-overlay | 点击遮罩层时触发 | - |
### Slots

View File

@ -4,7 +4,6 @@
v-model:show="show.lightTheme"
:actions="t('actions')"
placement="bottom-start"
class="foo"
@select="onSelect"
>
<template #reference>

View File

@ -148,3 +148,18 @@ test('should close popover when touch outside content', async () => {
trigger(document.body, 'touchstart');
expect(wrapper.emitted('update:show')[0][0]).toEqual(false);
});
test('should emit click-overlay event when overlay is clicked', () => {
const onClickOverlay = jest.fn();
const wrapper = mount(Popover, {
props: {
show: true,
overlay: true,
teleport: null,
onClickOverlay,
},
});
wrapper.find('.van-overlay').trigger('click');
expect(onClickOverlay).toHaveBeenCalledTimes(1);
});