Skip to content

Commit

Permalink
🐛 (editor) Fix outside click not working in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jan 26, 2023
1 parent 01c9691 commit 0fc82cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apps/builder/src/components/VariableSearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const VariableSearchInput = ({

useOutsideClick({
ref: dropdownRef,
handler: () => onClose,
handler: onClose,
})

useEffect(() => {
Expand Down Expand Up @@ -189,6 +189,7 @@ export const VariableSearchInput = ({
w="inherit"
shadow="lg"
onMouseDown={(e) => e.stopPropagation()}
onPointerDown={(e) => e.stopPropagation()}
>
{isCreateVariableButtonDisplayed && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ const TextBubbleEditorContent = ({
rememberedSelection.current = editor.selection
},
onKeyDown: handleKeyDown,
onClick: () => {
setIsVariableDropdownOpen(false)
},
}}
/>
{isVariableDropdownOpen && (
Expand Down
4 changes: 1 addition & 3 deletions apps/builder/src/hooks/useOutsideClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ type Handler = (event: MouseEvent) => void
type Props<T> = {
ref: RefObject<T>
handler: Handler
mouseEvent?: 'mousedown' | 'mouseup'
}

export const useOutsideClick = <T extends HTMLElement = HTMLElement>({
ref,
handler,
mouseEvent = 'mousedown',
}: Props<T>): void => {
const triggerHandlerIfOutside = (event: MouseEvent) => {
const el = ref?.current
Expand All @@ -22,5 +20,5 @@ export const useOutsideClick = <T extends HTMLElement = HTMLElement>({
handler(event)
}

useEventListener(mouseEvent, triggerHandlerIfOutside)
useEventListener('pointerdown', triggerHandlerIfOutside)
}

0 comments on commit 0fc82cf

Please sign in to comment.