Skip to content

Commit b2cc3ab

Browse files
akolsonclaude
andcommitted
scope click-outside check to each dropdown's own container
Replaces the global querySelectorAll('.dropdown-container') with a per-instance containerRef, so clicking one dropdown's trigger correctly closes the other instead of being treated as an inside click. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1ddc9b6 commit b2cc3ab

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components/toolbar/FormatDropdown.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22

33
<div
4+
ref="containerRef"
45
class="dropdown-container"
56
@keydown="handleContainerKeydown"
67
>
@@ -65,6 +66,7 @@
6566
showHeadersDropdown: isOpen,
6667
toggleHeadersDropdown: toggleDropdown,
6768
selectFormat,
69+
containerRef,
6870
} = useDropdowns();
6971
7072
const { handleFormatChange } = useToolbarActions();
@@ -193,6 +195,7 @@
193195
handleContainerKeydown,
194196
textFormatOptions$,
195197
formatOptions$,
198+
containerRef,
196199
};
197200
},
198201
});

contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components/toolbar/PasteDropdown.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22

33
<div
4+
ref="containerRef"
45
class="dropdown-container paste-button-container"
56
@keydown="handleContainerKeydown"
67
>
@@ -78,6 +79,7 @@
7879
pasteOptions,
7980
showPasteDropdown: isOpen,
8081
togglePasteDropdown: toggleDropdown,
82+
containerRef,
8183
} = useDropdowns();
8284
8385
const { handlePaste } = useToolbarActions();
@@ -214,6 +216,7 @@
214216
paste$,
215217
pasteOptions$,
216218
pasteOptionsMenu$,
219+
containerRef,
217220
};
218221
},
219222
});

contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/composables/useDropdowns.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,13 @@ export function useDropdowns() {
7777
selectedFormat.value = format.label;
7878
};
7979

80-
const handleClickOutside = event => {
81-
const dropdownContainers = document.querySelectorAll('.dropdown-container');
82-
let isOutside = true;
83-
84-
dropdownContainers.forEach(container => {
85-
if (container.contains(event.target)) {
86-
isOutside = false;
87-
}
88-
});
80+
const containerRef = ref(null);
8981

90-
if (isOutside) {
91-
closeAllDropdowns();
82+
const handleClickOutside = event => {
83+
if (!containerRef.value || containerRef.value.contains(event.target)) {
84+
return;
9285
}
86+
closeAllDropdowns();
9387
};
9488

9589
onMounted(() => {
@@ -149,5 +143,6 @@ export function useDropdowns() {
149143
togglePasteDropdown,
150144
selectFormat,
151145
updateSelectedFormat,
146+
containerRef,
152147
};
153148
}

0 commit comments

Comments
 (0)