From 12ebdf0ff0f742d5363527908a4a2721e41b00f2 Mon Sep 17 00:00:00 2001 From: Osama Sayegh Date: Tue, 13 Sep 2022 17:12:27 +0300 Subject: [PATCH] DEV: Convert experimental user menu tabs to links when they're active (#18158) This PR restores a small feature which was present in the old menu and allowed users to click on the active tab in the menu to navigate to some page that showed the same items in the menu but with more details. For example, if you switch to the PMs tab and then click on it again, currently nothing happens. However, with this change, clicking on the tab again will take you to your messages page at `/my/messages`. Note: plugins that register custom tabs in the menu can provide a `linkWhenActive` property for their tab if they wish to mimic core's tabs, but it's optional; if they don't provide one, the tab will do nothing if the user clicks on it again. Internal topic: t/73349. --- .../app/components/user-menu/menu-tab.hbs | 15 ++++ .../app/components/user-menu/menu-tab.js | 27 ++++++ .../app/components/user-menu/menu.hbs | 10 +-- .../app/components/user-menu/menu.js | 39 ++++++++- .../app/components/user-menu/tab-button.hbs | 15 ---- .../app/components/user-menu/tab-button.js | 3 - .../tests/acceptance/user-menu-test.js | 83 +++++++++++++++++++ 7 files changed, 168 insertions(+), 24 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/user-menu/menu-tab.hbs create mode 100644 app/assets/javascripts/discourse/app/components/user-menu/menu-tab.js delete mode 100644 app/assets/javascripts/discourse/app/components/user-menu/tab-button.hbs delete mode 100644 app/assets/javascripts/discourse/app/components/user-menu/tab-button.js diff --git a/app/assets/javascripts/discourse/app/components/user-menu/menu-tab.hbs b/app/assets/javascripts/discourse/app/components/user-menu/menu-tab.hbs new file mode 100644 index 00000000000..8e1e2c04eb2 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/user-menu/menu-tab.hbs @@ -0,0 +1,15 @@ + diff --git a/app/assets/javascripts/discourse/app/components/user-menu/menu-tab.js b/app/assets/javascripts/discourse/app/components/user-menu/menu-tab.js new file mode 100644 index 00000000000..0e01a83dd88 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/user-menu/menu-tab.js @@ -0,0 +1,27 @@ +import Component from "@glimmer/component"; + +export default class UserMenuTab extends Component { + get isActive() { + return this.args.tab.id === this.args.currentTabId; + } + + get classNames() { + const list = ["btn", "btn-flat", "btn-icon", "no-text", "user-menu-tab"]; + if (this.isActive) { + list.push("active"); + } + return list.join(" "); + } + + get id() { + return `user-menu-button-${this.args.tab.id}`; + } + + get tabIndex() { + return this.isActive ? "0" : "-1"; + } + + get ariaControls() { + return `quick-access-${this.args.tab.id}`; + } +} diff --git a/app/assets/javascripts/discourse/app/components/user-menu/menu.hbs b/app/assets/javascripts/discourse/app/components/user-menu/menu.hbs index 3f9bd5e972b..2bd85ea2fc9 100644 --- a/app/assets/javascripts/discourse/app/components/user-menu/menu.hbs +++ b/app/assets/javascripts/discourse/app/components/user-menu/menu.hbs @@ -11,23 +11,23 @@