Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@
window.addEventListener('resize', handleWindowResize, { passive: true });
}

document.addEventListener('click', handleClickOutside, { passive: true });
document.addEventListener('mousedown', handleClickOutside, { passive: true });
});

onUnmounted(() => {
Expand All @@ -544,7 +544,7 @@
} else {
window.removeEventListener('resize', handleWindowResize);
}
document.removeEventListener('click', handleClickOutside);
document.removeEventListener('mousedown', handleClickOutside);
});

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>

<div
ref="containerRef"
class="dropdown-container"
@keydown="handleContainerKeydown"
>
Expand Down Expand Up @@ -65,6 +66,7 @@
showHeadersDropdown: isOpen,
toggleHeadersDropdown: toggleDropdown,
selectFormat,
containerRef,
} = useDropdowns();

const { handleFormatChange } = useToolbarActions();
Expand Down Expand Up @@ -193,6 +195,7 @@
handleContainerKeydown,
textFormatOptions$,
formatOptions$,
containerRef,
};
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>

<div
ref="containerRef"
class="dropdown-container paste-button-container"
@keydown="handleContainerKeydown"
>
Expand Down Expand Up @@ -78,6 +79,7 @@
pasteOptions,
showPasteDropdown: isOpen,
togglePasteDropdown: toggleDropdown,
containerRef,
} = useDropdowns();

const { handlePaste } = useToolbarActions();
Expand Down Expand Up @@ -214,6 +216,7 @@
paste$,
pasteOptions$,
pasteOptionsMenu$,
containerRef,
};
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,27 @@ export function useDropdowns() {
selectedFormat.value = format.label;
};

const handleClickOutside = event => {
const dropdownContainers = document.querySelectorAll('.dropdown-container');
let isOutside = true;

dropdownContainers.forEach(container => {
if (container.contains(event.target)) {
isOutside = false;
}
});
const containerRef = ref(null);

if (isOutside) {
closeAllDropdowns();
// Each instance checks only its own container so
// clicking one dropdown's trigger closes the other.
const handleClickOutside = event => {
if (!containerRef.value || containerRef.value.contains(event.target)) {
return;
}
closeAllDropdowns();
};

onMounted(() => {
document.addEventListener('click', handleClickOutside);
document.addEventListener('mousedown', handleClickOutside);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The root cause analysis here is excellent — tracing the missing click events to two independent preventDefault() paths (ProseMirror's mouseup and ToolbarButton's @mousedown.prevent) and choosing mousedown as the fix point is well-reasoned. The change is minimal and precise.

// Setup editor listener when component mounts
setupEditorListener();
// Initial format detection
updateSelectedFormat();
});

onUnmounted(() => {
document.removeEventListener('click', handleClickOutside);
document.removeEventListener('mousedown', handleClickOutside);
if (offTransaction) offTransaction();
});

Expand Down Expand Up @@ -149,5 +145,6 @@ export function useDropdowns() {
togglePasteDropdown,
selectFormat,
updateSelectedFormat,
containerRef,
};
}
Loading