Skip to content

Commit 02d9244

Browse files
authored
Prevent dropdown to open when click on active anchor (#1072)
* Make sure dropdown is closed on click * Prevent dropdown to open when clicking active element * Prettier
1 parent af573c4 commit 02d9244

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Elastic.Markdown/Assets/pages-nav.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export function initNav() {
4747
if (!pagesNav) {
4848
return
4949
}
50+
51+
const pagesDropdown = $('#pages-dropdown')
52+
if (pagesDropdown) {
53+
const activeAnchor = $('a.pages-dropdown_active', pagesDropdown)
54+
activeAnchor?.addEventListener('mousedown', (e) => {
55+
e.preventDefault()
56+
})
57+
}
58+
5059
const allNavItems = $$('a', pagesNav)
5160
allNavItems.forEach((link) => {
5261
link.addEventListener('click', () => {

src/Elastic.Markdown/Slices/Layout/_TocTree.cshtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
@if (Model.IsPrimaryNavEnabled && current is { Group.Index: not null })
88
{
99
<div class="sticky top-0 py-6 bg-white z-10 border-b-1 border-grey-20 pr-4">
10-
<div class="block group border-1 border-grey-20 rounded-sm font-sans relative">
10+
<div id="pages-dropdown" class="block group border-1 border-grey-20 rounded-sm font-sans relative">
1111
<button class="w-full text-left grid grid-cols-[1fr_auto] cursor-pointer font-semibold gap-1 hover:text-black pl-4 pr-2 py-2 group-open:border-b-1 border-grey-20">
12-
<span>
12+
<div>
1313
<a
14-
class="hover:underline text-blue-elastic hover:text-blue-elastic-100"
14+
class="pages-dropdown_active hover:underline text-blue-elastic hover:text-blue-elastic-100"
1515
href="@current.Group.Index?.Url"
1616
@Htmx.GetNavHxAttributes(true)>
1717
@current.Group.Index?.NavigationTitle
1818
</a>
19-
</span>
19+
</div>
2020
<div class="flex items-center justify-center size-6 hover:bg-grey-20 rounded-sm">
2121
<svg
2222
xmlns="http://www.w3.org/2000/svg"

0 commit comments

Comments
 (0)