FIX: Navigate to search result url on click (#24414)

Broken in https://github.com/discourse/discourse/pull/24393
This commit is contained in:
Isaac Janzen 2023-11-16 08:04:49 -07:00 committed by GitHub
parent 69464cbbe2
commit 8db0eb2afd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 6 deletions

View File

@ -23,6 +23,9 @@ export default class Types extends Component {
@action
onClick(event) {
if (wantsNewWindow(event)) {
return;
}
this.routeToSearchResult(event);
}
@ -33,6 +36,8 @@ export default class Types extends Component {
event.preventDefault();
return false;
} else if (event.key === "Enter") {
event.preventDefault();
event.stopPropagation();
this.routeToSearchResult(event);
return false;
}
@ -43,12 +48,6 @@ export default class Types extends Component {
@action
routeToSearchResult(event) {
if (wantsNewWindow(event)) {
return;
}
event.preventDefault();
event.stopPropagation();
DiscourseURL.routeTo(event.target.href);
this.args.closeSearchMenu();
}

View File

@ -534,6 +534,28 @@ acceptance("Search - Glimmer - Authenticated", function (needs) {
);
});
test("topic results - topic search scope - clicking a search result navigates to topic url", async function (assert) {
await visit("/");
await click("#search-button");
await fillIn("#search-term", "Development");
await triggerKeyEvent(document.activeElement, "keyup", "Enter");
const firstSearchResult =
".search-menu .results li:nth-of-type(1) a.search-link";
const firstTopicResultUrl = "/t/development-mode-super-slow/2179";
assert.strictEqual(
query(firstSearchResult).getAttribute("href"),
firstTopicResultUrl
);
await click(firstSearchResult);
assert.strictEqual(
currentURL(),
firstTopicResultUrl,
"redirects to clicked search result url"
);
});
test("search menu keyboard navigation", async function (assert) {
const container = ".search-menu .results";
await visit("/");