Skip to content

Commit 3e7d9fc

Browse files
To1nedscho
authored andcommitted
js: add correct href to "Show all results..."
There was some js sourcery happening to make a click on the "Show all results..." entry in the search results dropdown go to the search page. Instead of doing the sourcery on click, set a proper `href` attribute on the `<a>`. This also makes browsers show a hand cursor when hovering the entry in the dropdown. Signed-off-by: Toon Claes <[email protected]>
1 parent 2f9f1f4 commit 3e7d9fc

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

assets/js/application.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,12 @@ var Search = {
223223
$("#show-results-label").text("No matching pages found.");
224224
return;
225225
}
226-
$("#show-results-label").text("Show all results...");
226+
227+
const language = document.querySelector("html")?.getAttribute("lang");
228+
$("#show-results-label")
229+
.text("Show all results...")
230+
.attr('href', `${baseURLPrefix}search/results?search=${term}${language && `&language=${language}`}`);
231+
227232
const loadButton = $("#load-more-results");
228233
loadButton.text(`Loading ${
229234
results.results.length < 2
@@ -300,11 +305,6 @@ var Search = {
300305
selectResultOption: function() {
301306
var link = $('#search-results a')[Search.selectedIndex];
302307
var url = $(link).attr('href');
303-
if(!url) {
304-
const term = $('#search-text').val();
305-
const language = document.querySelector("html")?.getAttribute("lang");
306-
url = `${baseURLPrefix}search/results?search=${term}${language && `&language=${language}`}`;
307-
}
308308
window.location.href = url;
309309
selectedIndex = 0;
310310
},

tests/git-scm.spec.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ test('search', async ({ page }) => {
115115
// Expect the first search result to be "git-commit"
116116
const searchResults = page.locator('#search-results')
117117
await expect(searchResults.getByRole("link")).not.toHaveCount(0)
118-
await expect(searchResults.getByRole("link").nth(0)).toHaveText('git-commit')
118+
await expect(searchResults.getByRole("link").nth(0)).toHaveText('Show all results...')
119+
await expect(searchResults.getByRole("link").nth(1)).toHaveText('git-commit')
119120

120121
// Expect the search page to show up
121122
await searchBox.press('Enter')
@@ -137,7 +138,8 @@ test('search', async ({ page }) => {
137138
await page.goto(`${url}docs/git-commit/fr`)
138139
await searchBox.fill('add')
139140
await searchBox.press('Shift')
140-
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
141+
await expect(searchResults.getByRole("link").nth(0)).toHaveAttribute('href', /\/search\/results\?search=add&language=fr$/)
142+
await expect(searchResults.getByRole("link").nth(1)).toHaveAttribute('href', /\/docs\/git-add\/fr(\.html)?$/)
141143

142144
// pressing the Enter key should navigate to the full search results page
143145
await searchBox.press('Enter')

0 commit comments

Comments
 (0)