fix(Popover): close-on-click-outside not work (#8352)

This commit is contained in:
neverland 2021-03-15 20:05:45 +08:00 committed by GitHub
parent d9c51b9070
commit 40a1b27c5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 3 deletions

View File

@ -85,6 +85,10 @@ export default defineComponent({
type: Boolean, type: Boolean,
default: true, default: true,
}, },
closeOnClickOutside: {
type: Boolean,
default: true,
},
}, },
emits: ['select', 'touchstart', 'update:show'], emits: ['select', 'touchstart', 'update:show'],
@ -158,7 +162,10 @@ export default defineComponent({
}; };
const onClickAway = () => { const onClickAway = () => {
if (!props.overlay || props.closeOnClickOverlay) { if (
props.closeOnClickOutside &&
(!props.overlay || props.closeOnClickOverlay)
) {
updateShow(false); updateShow(false);
} }
}; };

View File

@ -175,3 +175,15 @@ test('should not close Popover when overlay is clicked and close-on-click-overla
trigger(overlay, 'touchstart'); trigger(overlay, 'touchstart');
expect(wrapper.emitted('update:show')).toBeFalsy(); expect(wrapper.emitted('update:show')).toBeFalsy();
}); });
test('should not close Popover when outside is clicked and close-on-click-outside is false', () => {
const wrapper = mount(Popover, {
props: {
show: true,
closeOnClickOutside: false,
},
});
trigger(document.body, 'touchstart');
expect(wrapper.emitted('update:show')).toBeFalsy();
});

View File

@ -1,6 +1,8 @@
import {isDef} from "./base"; import { isDef } from './base';
export function deepClone<T extends Record<string, any> | null | undefined>(obj: T): T { export function deepClone<T extends Record<string, any> | null | undefined>(
obj: T
): T {
if (!isDef(obj)) { if (!isDef(obj)) {
return obj; return obj;
} }