FIX: icon toggles saerch menu display on click (#20950)

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
https://github.com/discourse/discourse/pull/14788)
This commit is contained in:
Penar Musaraj 2023-04-04 09:49:55 -04:00 committed by GitHub
parent 7658341b0b
commit 17ba00c395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -348,8 +348,10 @@ export default createWidget("search-menu", {
}); });
}, },
mouseDownOutside() { clickOutside() {
this.sendWidgetAction("toggleSearchMenu"); if (this.key === "search-menu" && !window.getSelection().toString()) {
this.sendWidgetAction("toggleSearchMenu");
}
}, },
clearTopicContext() { clearTopicContext() {

View File

@ -15,7 +15,7 @@ import {
import I18n from "I18n"; import I18n from "I18n";
import searchFixtures from "discourse/tests/fixtures/search-fixtures"; import searchFixtures from "discourse/tests/fixtures/search-fixtures";
import selectKit from "discourse/tests/helpers/select-kit-helper"; 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"; import { DEFAULT_TYPE_FILTER } from "discourse/widgets/search-menu";
acceptance("Search - Anonymous", function (needs) { acceptance("Search - Anonymous", function (needs) {
@ -114,8 +114,7 @@ acceptance("Search - Anonymous", function (needs) {
); );
}); });
// TODO: This feature doesn't work currently (/t/69760) test("search button toggles search menu", async function (assert) {
skip("search button toggles search menu", async function (assert) {
await visit("/"); await visit("/");
await click("#search-button"); await click("#search-button");