Skip to content

Commit 4615460

Browse files
J-MichalekJakubzernonia
authored
perf(Editable): track pointerdown only in editing mode (#1945)
* perf(editable): track pointerdown only in editing mode * chore(dismissable-layer): remove overlooked console.log * fix: editable requires double click to dismiss --------- Co-authored-by: Jakub <jakub.michalek@freelo.io> Co-authored-by: zernonia <zernonia@gmail.com>
1 parent 0307427 commit 4615460

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

packages/core/src/DismissableLayer/utils.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Ref } from 'vue'
1+
import type { MaybeRefOrGetter, Ref } from 'vue'
22
import { isClient } from '@vueuse/shared'
3-
import { nextTick, ref, watchEffect } from 'vue'
3+
import { nextTick, ref, toValue, watchEffect } from 'vue'
44
import { handleAndDispatchCustomEvent } from '@/shared'
55

66
export type PointerDownOutsideEvent = CustomEvent<{
@@ -45,6 +45,7 @@ function isLayerExist(layerElement: HTMLElement, targetElement: HTMLElement) {
4545
export function usePointerDownOutside(
4646
onPointerDownOutside?: (event: PointerDownOutsideEvent) => void,
4747
element?: Ref<HTMLElement | undefined>,
48+
enabled: MaybeRefOrGetter<boolean> = true,
4849
) {
4950
const ownerDocument: Document
5051
= element?.value?.ownerDocument ?? globalThis?.document
@@ -53,7 +54,7 @@ export function usePointerDownOutside(
5354
const handleClickRef = ref(() => {})
5455

5556
watchEffect((cleanupFn) => {
56-
if (!isClient)
57+
if (!isClient || !toValue(enabled))
5758
return
5859
const handlePointerDown = async (event: PointerEvent) => {
5960
const target = event.target as HTMLElement | undefined
@@ -132,7 +133,11 @@ export function usePointerDownOutside(
132133
})
133134

134135
return {
135-
onPointerDownCapture: () => (isPointerInsideDOMTree.value = true),
136+
onPointerDownCapture: () => {
137+
if (!toValue(enabled))
138+
return
139+
isPointerInsideDOMTree.value = true
140+
},
136141
}
137142
}
138143

packages/core/src/Editable/EditableRoot.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ function handleDismiss() {
180180
}
181181
}
182182
183-
const pointerDownOutside = usePointerDownOutside(() => handleDismiss(), currentElement)
183+
const pointerDownOutside = usePointerDownOutside(() => handleDismiss(), currentElement, isEditing)
184184
const focusOutside = useFocusOutside(() => handleDismiss(), currentElement)
185185
const isEmpty = computed(() => modelValue.value === '')
186186

0 commit comments

Comments
 (0)