Skip to content

Commit

Permalink
FIX: icon toggles saerch menu display on click (discourse#20950)
Browse files Browse the repository at this point in the history
Using the `mouseDownOutside` event was problematic here because two
events were being triggered consecutively: `mouseDown`
would toggle the menu off and `click` would then toggle it back on. This
switches the logic to use `clickOutside` again, but with two changes:
- it limits the action to the `search-menu` key (so that theme component
overrides can do their own handling)
- it does not trigger the event when there is an active text selection
 (this was the original reason for switching to `mouseDownOutside`, see
discourse#14788)
  • Loading branch information
pmusaraj committed Apr 4, 2023
1 parent 7658341 commit 17ba00c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/assets/javascripts/discourse/app/widgets/search-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,10 @@ export default createWidget("search-menu", {
});
},

mouseDownOutside() {
this.sendWidgetAction("toggleSearchMenu");
clickOutside() {
if (this.key === "search-menu" && !window.getSelection().toString()) {
this.sendWidgetAction("toggleSearchMenu");
}
},

clearTopicContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import I18n from "I18n";
import searchFixtures from "discourse/tests/fixtures/search-fixtures";
import selectKit from "discourse/tests/helpers/select-kit-helper";
import { skip, test } from "qunit";
import { test } from "qunit";
import { DEFAULT_TYPE_FILTER } from "discourse/widgets/search-menu";

acceptance("Search - Anonymous", function (needs) {
Expand Down Expand Up @@ -114,8 +114,7 @@ acceptance("Search - Anonymous", function (needs) {
);
});

// TODO: This feature doesn't work currently (/t/69760)
skip("search button toggles search menu", async function (assert) {
test("search button toggles search menu", async function (assert) {
await visit("/");

await click("#search-button");
Expand Down

0 comments on commit 17ba00c

Please sign in to comment.