Skip to content

Commit 1735884

Browse files
authored
Merge pull request #5926 from akolson/auto-close-rte-menus-on-click
Close RTE dropdowns on mousedown instead of click
2 parents e08a3da + d33cff7 commit 1735884

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

contentcuration/contentcuration/frontend/shared/views/TipTapEditor/TipTapEditor/components/EditorToolbar.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@
535535
window.addEventListener('resize', handleWindowResize, { passive: true });
536536
}
537537
538-
document.addEventListener('click', handleClickOutside, { passive: true });
538+
document.addEventListener('mousedown', handleClickOutside, { passive: true });
539539
});
540540
541541
onUnmounted(() => {
@@ -544,7 +544,7 @@
544544
} else {
545545
window.removeEventListener('resize', handleWindowResize);
546546
}
547-
document.removeEventListener('click', handleClickOutside);
547+
document.removeEventListener('mousedown', handleClickOutside);
548548
});
549549
550550
return {

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: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,27 @@ 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+
// Each instance checks only its own container so
83+
// clicking one dropdown's trigger closes the other.
84+
const handleClickOutside = event => {
85+
if (!containerRef.value || containerRef.value.contains(event.target)) {
86+
return;
9287
}
88+
closeAllDropdowns();
9389
};
9490

9591
onMounted(() => {
96-
document.addEventListener('click', handleClickOutside);
92+
document.addEventListener('mousedown', handleClickOutside);
9793
// Setup editor listener when component mounts
9894
setupEditorListener();
9995
// Initial format detection
10096
updateSelectedFormat();
10197
});
10298

10399
onUnmounted(() => {
104-
document.removeEventListener('click', handleClickOutside);
100+
document.removeEventListener('mousedown', handleClickOutside);
105101
if (offTransaction) offTransaction();
106102
});
107103

@@ -149,5 +145,6 @@ export function useDropdowns() {
149145
togglePasteDropdown,
150146
selectFormat,
151147
updateSelectedFormat,
148+
containerRef,
152149
};
153150
}

0 commit comments

Comments
 (0)