diff --git a/assets/search/js/dropdown.ts b/assets/search/js/dropdown.ts index 117612fe9b5..af21427d9a6 100644 --- a/assets/search/js/dropdown.ts +++ b/assets/search/js/dropdown.ts @@ -4,6 +4,14 @@ dropdown.setAttribute('aria-expanded', 'false') } + const hideAll = (except: null|HTMLElement) => { + document.querySelectorAll('.search-dropdown.show').forEach((dropdown) => { + if (dropdown != except) { + hide(dropdown) + } + }) + } + const show = (dropdown: HTMLElement) => { dropdown.classList.add('show') dropdown.setAttribute('aria-expanded', 'true') @@ -16,6 +24,7 @@ } show(dropdown) + hideAll(dropdown) } document.addEventListener('DOMContentLoaded', () => { @@ -98,9 +107,7 @@ } // close opened dropdown when losing focus. - document.querySelectorAll('.search-dropdown.show').forEach((dropdown) => { - hide(dropdown) - }) + hideAll() }) }) })()