A platform for community discussion. Free, open, simple.
Fix firefox cmd click search dropdown (#39947)
Régis Hanole3ca36551f4b
diff --git a/frontend/discourse/app/components/search-menu/results/type/topic.gjs b/frontend/discourse/app/components/search-menu/results/type/topic.gjsindex b5d62427feb..63213406abb 100644--- a/frontend/discourse/app/components/search-menu/results/type/topic.gjs+++ b/frontend/discourse/app/components/search-menu/results/type/topic.gjs@@ -6,11 +6,18 @@ import HighlightedSearch from "discourse/components/search-menu/highlighted-searimport Blurb from "discourse/components/search-menu/results/blurb";import TopicStatus from "discourse/components/topic-status";import lazyHash from "discourse/helpers/lazy-hash";-import { and } from "discourse/truth-helpers";import dCategoryLink from "discourse/ui-kit/helpers/d-category-link";import dDiscourseTags from "discourse/ui-kit/helpers/d-discourse-tags";import dReplaceEmoji from "discourse/ui-kit/helpers/d-replace-emoji";+const MaybeAnchor = <template>+ {{#if @href}}+ <a href={{@href}}>{{yield}}</a>+ {{else}}+ {{yield}}+ {{/if}}+</template>;+export default class Results extends Component {@service siteSettings;@@ -19,6 +26,13 @@ export default class Results extends Component {return this.args.result.topic.isPrivateMessage && !this.args.isPMOnly;}+ get useHeadline() {+ return (+ this.siteSettings.use_pg_headlines_for_excerpt &&+ this.args.result.topic_title_headline+ );+ }+<template><span class="topic"><span class="first-line">@@ -29,20 +43,13 @@ export default class Results extends Component {@showPrivateMessageIcon={{this.shouldShowPrivateMessageIcon}}/><span class="topic-title" data-topic-id={{@result.topic.id}}>- {{#if- (and- this.siteSettings.use_pg_headlines_for_excerpt- @result.topic_title_headline- )- }}- <a href={{if @withTopicUrl @result.url}}>+ <MaybeAnchor @href={{if @withTopicUrl @result.url}}>+ {{#if this.useHeadline}}{{dReplaceEmoji (trustHTML @result.topic_title_headline)}}- </a>- {{else}}- <a href={{if @withTopicUrl @result.url}}>+ {{else}}<HighlightedSearch @string={{@result.topic.fancyTitle}} />- </a>- {{/if}}+ {{/if}}+ </MaybeAnchor><PluginOutlet@name="search-menu-results-topic-title-suffix"@outletArgs={{lazyHash [email protected]}}diff --git a/frontend/discourse/app/components/topic-status.gjs b/frontend/discourse/app/components/topic-status.gjsindex 47a95831644..08b8356e26d 100644--- a/frontend/discourse/app/components/topic-status.gjs+++ b/frontend/discourse/app/components/topic-status.gjs@@ -31,11 +31,18 @@ export default class TopicStatus extends Component {{{~! no whitespace ~}}<this.wrapperElement class="topic-statuses">{{~#if @topic.bookmarked~}}- <a- href={{@topic.url}}- title={{i18n "topic_statuses.bookmarked.help"}}- class="topic-status --bookmarked"- >{{dIcon "bookmark"}}</a>+ {{~#if this.canAct~}}+ <a+ href={{@topic.url}}+ title={{i18n "topic_statuses.bookmarked.help"}}+ class="topic-status --bookmarked"+ >{{dIcon "bookmark"}}</a>+ {{~else~}}+ <span+ title={{i18n "topic_statuses.bookmarked.help"}}+ class="topic-status --bookmarked"+ >{{dIcon "bookmark"}}</span>+ {{~/if~}}{{~/if~}}{{~#if (and @topic.closed @topic.archived)~}}diff --git a/frontend/discourse/tests/integration/components/search-menu/results/type/topic-test.gjs b/frontend/discourse/tests/integration/components/search-menu/results/type/topic-test.gjsindex 1eeeeb9ba85..11ee7383ac2 100644--- a/frontend/discourse/tests/integration/components/search-menu/results/type/topic-test.gjs+++ b/frontend/discourse/tests/integration/components/search-menu/results/type/topic-test.gjs@@ -75,5 +75,76 @@ module(.dom(".topic-status .d-icon-envelope").doesNotExist("PM icon not shown for regular topic");});++ test("does not wrap title in an anchor without @withTopicUrl", async function (assert) {+ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic", {+ id: 4,+ title: "Topic Without URL",+ });++ await render(+ <template>+ <TopicResultComponent @result={{hash topic=topic url="/t/foo/4"}} />+ </template>+ );++ assert+ .dom(".topic-title a")+ .doesNotExist(+ "title is not wrapped in an anchor when @withTopicUrl is not passed"+ );+ });++ test("wraps title in an anchor with @withTopicUrl", async function (assert) {+ const store = getOwner(this).lookup("service:store");+ const topic = store.createRecord("topic", {+ id: 5,+ title: "Topic With URL",+ });++ await render(+ <template>+ <TopicResultComponent+ @result={{hash topic=topic url="/t/foo/5"}}+ @withTopicUrl={{true}}+ />+ </template>+ );++ assert+ .dom(".topic-title a")+ .hasAttribute(+ "href",+ "/t/foo/5",+ "title is wrapped in an anchor pointing to result.url"+ );+ });++ test("bookmark status icon is not an anchor in the search dropdown", async function (assert) {+ const store = getOwner(this).lookup("service:store");+ const bookmarkedTopic = store.createRecord("topic", {+ id: 6,+ title: "Bookmarked Topic",+ bookmarked: true,+ });++ await render(+ <template>+ <TopicResultComponent+ @result={{hash topic=bookmarkedTopic url="/t/foo/6"}}+ />+ </template>+ );++ assert+ .dom(".topic-status.--bookmarked")+ .exists("bookmark icon renders for bookmarked topic");+ assert+ .dom("a.topic-status.--bookmarked")+ .doesNotExist(+ "bookmark icon is not an anchor when actions are disabled"+ );+ });});