From 2f428023dae020284139e8b2a5e262a5f505e544 Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Wed, 14 Sep 2022 01:25:40 +0300 Subject: [PATCH] DEV: ctrl+click on user menu items should open in new tab (#18243) --- .../discourse/app/lib/user-menu/base-item.js | 4 ++++ .../tests/acceptance/user-menu-test.js | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js b/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js index ab5fb90c379..817bf106f0c 100644 --- a/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js +++ b/app/assets/javascripts/discourse/app/lib/user-menu/base-item.js @@ -1,4 +1,5 @@ import DiscourseURL from "discourse/lib/url"; +import { wantsNewWindow } from "discourse/lib/intercept-click"; export default class UserMenuBaseItem { get className() {} @@ -30,6 +31,9 @@ export default class UserMenuBaseItem { get topicId() {} onClick({ event, closeUserMenu }) { + if (wantsNewWindow(event)) { + return; + } closeUserMenu(); const href = this.linkHref; if (href) { diff --git a/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js b/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js index f95512912da..000f7999e97 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/user-menu-test.js @@ -112,6 +112,25 @@ acceptance("User menu", function (needs) { exists(".user-menu"), "clicking on the same item again closes the menu" ); + + await click(".d-header-icons .current-user"); + await click("#user-menu-button-review-queue"); + // this may not be ideal because it actually attempts to open a new tab + // which gets blocked by the browser, but otherwise it seems harmless and + // doesn't cause the test to fail. if it causes problems for you, feel free + // to remove the ctrl+click tests. + await click("#quick-access-review-queue li.reviewable.reviewed a", { + ctrlKey: true, + }); + assert.strictEqual( + currentURL(), + "/review/17", + "ctrl-clicking on an item doesn't navigate to a new page" + ); + assert.ok( + exists(".user-menu"), + "ctrl-clicking on an item doesn't close the menu" + ); }); test("tabs added via the plugin API", async function (assert) {