fix: global `mousedown` handler in picker input hooks (#5657)

pull/5669/head
Gin 2022-06-03 14:28:44 +08:00 committed by GitHub
parent 3cd7ca3e0b
commit 18ce00d239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 22 deletions

View File

@ -1,5 +1,5 @@
import type { ComputedRef, HTMLAttributes, Ref } from 'vue'; import type { ComputedRef, HTMLAttributes, Ref } from 'vue';
import { onBeforeUnmount, watchEffect, watch, ref, computed } from 'vue'; import { onBeforeUnmount, onMounted, watch, ref, computed } from 'vue';
import type { FocusEventHandler } from '../../_util/EventInterface'; import type { FocusEventHandler } from '../../_util/EventInterface';
import KeyCode from '../../_util/KeyCode'; import KeyCode from '../../_util/KeyCode';
import { addGlobalMousedownEvent, getTargetFromEvent } from '../utils/uiUtil'; import { addGlobalMousedownEvent, getTargetFromEvent } from '../utils/uiUtil';
@ -148,14 +148,11 @@ export default function usePickerInput({
}); });
const globalMousedownEvent = ref(); const globalMousedownEvent = ref();
// Global click handler // Global click handler
watchEffect( onMounted(() => {
() => globalMousedownEvent.value = addGlobalMousedownEvent((e: MouseEvent) => {
globalMousedownEvent.value &&
globalMousedownEvent.value()(
(globalMousedownEvent.value = addGlobalMousedownEvent((e: MouseEvent) => {
const target = getTargetFromEvent(e); const target = getTargetFromEvent(e);
if (open) { if (open.value) {
const clickedOutside = isClickOutside(target); const clickedOutside = isClickOutside(target);
if (!clickedOutside) { if (!clickedOutside) {
@ -169,9 +166,8 @@ export default function usePickerInput({
triggerOpen(false); triggerOpen(false);
} }
} }
})), });
), });
);
onBeforeUnmount(() => { onBeforeUnmount(() => {
globalMousedownEvent.value && globalMousedownEvent.value(); globalMousedownEvent.value && globalMousedownEvent.value();
}); });