From ce059a909b78841015a590ea583e8cb4d343673f Mon Sep 17 00:00:00 2001 From: John Cowen Date: Fri, 31 Jan 2020 14:11:46 +0000 Subject: [PATCH] ui: Fix sticky nspace menu (#7164) * ui: Fix typo expanded > ariaExpanded * ui: Add the things we need to test this * ui: Add tests for testing the menu closes when clicked * ui: Ensure the aria-menu closes on route change --- ui-v2/app/components/aria-menu.js | 6 ++ .../templates/components/hashicorp-consul.hbs | 2 +- .../app/templates/components/popover-menu.hbs | 2 +- .../acceptance/dc/nspaces/manage.feature | 33 ++++++++++ .../steps/dc/nspaces/manage-steps.js | 10 +++ ui-v2/tests/pages/components/page.js | 8 ++- ui-v2/tests/steps/assertions/page.js | 64 +++++++++++++++---- 7 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 ui-v2/tests/acceptance/dc/nspaces/manage.feature create mode 100644 ui-v2/tests/acceptance/steps/dc/nspaces/manage-steps.js diff --git a/ui-v2/app/components/aria-menu.js b/ui-v2/app/components/aria-menu.js index 50f63afa4..2c1daff70 100644 --- a/ui-v2/app/components/aria-menu.js +++ b/ui-v2/app/components/aria-menu.js @@ -39,6 +39,7 @@ const MENU_ITEMS = '[role^="menuitem"]'; export default Component.extend({ tagName: '', dom: service('dom'), + router: service('router'), guid: '', expanded: false, orientation: 'vertical', @@ -47,6 +48,7 @@ export default Component.extend({ this._super(...arguments); set(this, 'guid', this.dom.guid(this)); this._listeners = this.dom.listeners(); + this._routelisteners = this.dom.listeners(); }, didInsertElement: function() { // TODO: How do you detect whether the children have changed? @@ -54,10 +56,14 @@ export default Component.extend({ this.$menu = this.dom.element(`#${COMPONENT_ID}menu-${this.guid}`); const labelledBy = this.$menu.getAttribute('aria-labelledby'); this.$trigger = this.dom.element(`#${labelledBy}`); + this._routelisteners.add(this.router, { + routeWillChange: () => this.actions.close.apply(this, [{}]), + }); }, willDestroyElement: function() { this._super(...arguments); this._listeners.remove(); + this._routelisteners.remove(); }, actions: { keypressClick: function(e) { diff --git a/ui-v2/app/templates/components/hashicorp-consul.hbs b/ui-v2/app/templates/components/hashicorp-consul.hbs index 37d73e1e5..f6f844b71 100644 --- a/ui-v2/app/templates/components/hashicorp-consul.hbs +++ b/ui-v2/app/templates/components/hashicorp-consul.hbs @@ -12,7 +12,7 @@ {{#if dc}}