From 7a05a9d4110cd3ad8c085750b9e2eb6590aeb75e Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 16 Aug 2022 13:45:32 +0800 Subject: [PATCH] UX: Make Sidebar more consistent with user menu on mobile (#17940) Before this commit, we carried custom code and styles for the sidebar on mobile. This meant the look and feel of bringing up the sidebar on mobile was very different from the user menu resulting in a very inconsistent experience on mobile. Also, we could not leverage on the existing swipe to close support on mobile. In this commit, we made it such that the sidebar dropdown is always rendered on mobile and made the interaction with the dropdown more consistent with the user menu. There is also more parity with the old hamburger dropdown when the experimental sidebar is disabled. --- .../components/sidebar/hamburger-dropdown.js | 12 +++++ .../discourse/app/components/site-header.js | 23 +++++++++ .../discourse/app/controllers/application.js | 5 ++ .../components/sidebar/hamburger-dropdown.hbs | 4 +- .../discourse/app/widgets/header.js | 2 +- .../tests/acceptance/sidebar-mobile-test.js | 30 +++-------- .../stylesheets/common/base/menu-panel.scss | 28 ---------- .../common/base/sidebar-footer.scss | 2 +- .../base/sidebar-more-section-links.scss | 8 ++- .../stylesheets/desktop/menu-panel.scss | 28 ++++++++++ app/assets/stylesheets/mobile/discourse.scss | 51 ------------------- 11 files changed, 86 insertions(+), 107 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/sidebar/hamburger-dropdown.js diff --git a/app/assets/javascripts/discourse/app/components/sidebar/hamburger-dropdown.js b/app/assets/javascripts/discourse/app/components/sidebar/hamburger-dropdown.js new file mode 100644 index 00000000000..d2fd84a4384 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/sidebar/hamburger-dropdown.js @@ -0,0 +1,12 @@ +import Component from "@glimmer/component"; +import { action } from "@ember/object"; +import { inject as service } from "@ember/service"; + +export default class SidebarHamburgerDropdown extends Component { + @service appEvents; + + @action + triggerRenderedAppEvent() { + this.appEvents.trigger("sidebar-hamburger-dropdown:rendered"); + } +} diff --git a/app/assets/javascripts/discourse/app/components/site-header.js b/app/assets/javascripts/discourse/app/components/site-header.js index b5a4dc205dc..888c050fda0 100644 --- a/app/assets/javascripts/discourse/app/components/site-header.js +++ b/app/assets/javascripts/discourse/app/components/site-header.js @@ -225,6 +225,17 @@ const SiteHeaderComponent = MountWidget.extend( this.appEvents.on("user-menu:rendered", this, "_animateMenu"); } + if ( + this.siteSettings.enable_experimental_sidebar_hamburger && + !this.sidebarEnabled + ) { + this.appEvents.on( + "sidebar-hamburger-dropdown:rendered", + this, + "_animateMenu" + ); + } + this.dispatch("notifications:changed", "user-notifications"); this.dispatch("header:keyboard-trigger", "header"); this.dispatch("user-menu:navigation", "user-menu"); @@ -341,6 +352,17 @@ const SiteHeaderComponent = MountWidget.extend( this.appEvents.off("user-menu:rendered", this, "_animateMenu"); } + if ( + this.siteSettings.enable_experimental_sidebar_hamburger && + !this.sidebarEnabled + ) { + this.appEvents.off( + "sidebar-hamburger-dropdown:rendered", + this, + "_animateMenu" + ); + } + if (this.currentUser) { this.currentUser.off("status-changed", this, "queueRerender"); } @@ -373,6 +395,7 @@ const SiteHeaderComponent = MountWidget.extend( _animateMenu() { const menuPanels = document.querySelectorAll(".menu-panel"); + if (menuPanels.length === 0) { if (this.site.mobileView) { this._animate = true; diff --git a/app/assets/javascripts/discourse/app/controllers/application.js b/app/assets/javascripts/discourse/app/controllers/application.js index b91d46572f1..b6d0f25c8bd 100644 --- a/app/assets/javascripts/discourse/app/controllers/application.js +++ b/app/assets/javascripts/discourse/app/controllers/application.js @@ -74,6 +74,11 @@ export default Controller.extend({ return false; } + // Always return dropdown on mobile + if (this.site.mobileView) { + return false; + } + return enableSidebar; }, diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs index 3167355bc97..437f5ba090a 100644 --- a/app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs @@ -1,7 +1,7 @@
-