Skip to content

Commit 70385c1

Browse files
Add listener to close drop down for click anywhere on page
1 parent 5907e6a commit 70385c1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

layouts/partials/md-dropdown.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<details class="group relative z-50 inline-block" data-heap-id="markdown-dropdown">
1+
<details id="markdownDropdown" class="group relative z-50 inline-block" data-heap-id="markdown-dropdown">
22
<summary
33
class="inline-flex cursor-pointer items-center gap-2 rounded border border-gray-light-200 bg-gray-light-200 px-4 py-2 text-base font-semibold text-black transition-colors hover:bg-gray-light-300 dark:border-gray-dark-200 dark:bg-gray-dark-300 dark:text-white dark:hover:bg-gray-dark-400"
44
data-heap-id="markdown-dropdown-toggle"
@@ -100,4 +100,17 @@
100100
alert("Couldn't find Docs AI.");
101101
}
102102
}
103+
104+
document.addEventListener('click', function (event) {
105+
const dropdown = document.getElementById('markdownDropdown');
106+
107+
if (!dropdown) return;
108+
109+
const isClickInside = dropdown.contains(event.target);
110+
111+
// If dropdown is open and click was outside, close it
112+
if (!isClickInside && dropdown.hasAttribute('open')) {
113+
dropdown.removeAttribute('open');
114+
}
115+
});
103116
</script>

0 commit comments

Comments
 (0)