Skip to content

Commit fdddc9f

Browse files
committed
Fix search dropdown behaviour
After this change: | Scenario | Behavior | |----------|----------| | Type search, click result | Navigate without `?q=`, clean URL without dropdown | | Type search, press Enter | Navigate without `?q=`, clean URL without dropdown | | Land on URL with `?q=` param | Show dropdown with pre-filled query | | Click outside dropdown | Hide dropdown, keep input value | | Focus input with existing query | Show dropdown again |
1 parent 85ac545 commit fdddc9f

File tree

1 file changed

+17
-15
lines changed
  • lib/rdoc/generator/template/aliki/js

1 file changed

+17
-15
lines changed

lib/rdoc/generator/template/aliki/js/aliki.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,7 @@ function createSearchInstance(input, result) {
6767
}
6868

6969
search.select = function(result) {
70-
let href = result.firstChild.firstChild.href;
71-
const query = this.input.value;
72-
if (query) {
73-
const url = new URL(href, window.location.origin);
74-
url.searchParams.set('q', query);
75-
url.searchParams.set('nav', '0');
76-
href = url.toString();
77-
}
78-
window.location.href = href;
70+
window.location.href = result.firstChild.firstChild.href;
7971
}
8072

8173
search.scrollIntoView = search.scrollInWindow;
@@ -97,15 +89,27 @@ function hookSearch() {
9789
const search = createSearchInstance(input, result);
9890
if (!search) return;
9991

92+
// Hide search results when clicking outside the search area
93+
document.addEventListener('click', (e) => {
94+
if (!e.target.closest('.navbar-search-desktop')) {
95+
result.setAttribute('aria-expanded', 'false');
96+
}
97+
});
98+
99+
// Show search results when focusing on input (if there's a query)
100+
input.addEventListener('focus', () => {
101+
if (input.value.trim()) {
102+
result.setAttribute('aria-expanded', 'true');
103+
}
104+
});
105+
100106
// Check for ?q= URL parameter and trigger search automatically
101107
if (typeof URLSearchParams !== 'undefined') {
102108
const urlParams = new URLSearchParams(window.location.search);
103109
const queryParam = urlParams.get('q');
104110
if (queryParam) {
105-
const navParam = urlParams.get('nav');
106-
const autoSelect = navParam !== '0';
107111
input.value = queryParam;
108-
search.search(queryParam, autoSelect);
112+
search.search(queryParam, false);
109113
}
110114
}
111115
}
@@ -378,9 +382,7 @@ function hookSearchModal() {
378382
if (queryParam && isSmallViewport) {
379383
openSearchModal();
380384
searchInput.value = queryParam;
381-
const navParam = urlParams.get('nav');
382-
const autoSelect = navParam !== '0';
383-
mobileSearch.search(queryParam, autoSelect);
385+
mobileSearch.search(queryParam, false);
384386
}
385387
}
386388
}

0 commit comments

Comments
 (0)