Skip to content

Commit

Permalink
fix(ue): display at most one dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Oct 25, 2024
1 parent c6bea3a commit b670c84
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions assets/search/js/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
dropdown.setAttribute('aria-expanded', 'false')
}

const hideAll = (except: null|HTMLElement) => {
document.querySelectorAll<HTMLElement>('.search-dropdown.show').forEach((dropdown) => {
if (dropdown != except) {
hide(dropdown)
}
})
}

const show = (dropdown: HTMLElement) => {
dropdown.classList.add('show')
dropdown.setAttribute('aria-expanded', 'true')
Expand All @@ -16,6 +24,7 @@
}

show(dropdown)
hideAll(dropdown)
}

document.addEventListener('DOMContentLoaded', () => {
Expand Down Expand Up @@ -98,9 +107,7 @@
}

// close opened dropdown when losing focus.
document.querySelectorAll<HTMLElement>('.search-dropdown.show').forEach((dropdown) => {
hide(dropdown)
})
hideAll()
})
})
})()

0 comments on commit b670c84

Please sign in to comment.