From 5c4b06730b903bf410cd22b53f94efb69a5b4521 Mon Sep 17 00:00:00 2001 From: Ryan Murphy Date: Sat, 4 Nov 2023 16:08:55 -0400 Subject: [PATCH] Fix navigation behavior on enterprise panel tabs --- .../controllers/tabs_and_panels_controller.js | 10 ++++++++++ spec/system/admin/enterprises_spec.rb | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/app/webpacker/controllers/tabs_and_panels_controller.js b/app/webpacker/controllers/tabs_and_panels_controller.js index d3ea9a44fe..050a4fff25 100644 --- a/app/webpacker/controllers/tabs_and_panels_controller.js +++ b/app/webpacker/controllers/tabs_and_panels_controller.js @@ -37,6 +37,16 @@ export default class extends Controller { window.addEventListener("tabs-and-panels:click", (event) => { this.simulateClick(event.detail.tab, event.detail.panel); }); + + window.addEventListener("popstate", (event) => { + const newPanelId = event.target.location.hash.replace("#/", ""); + const currentPanelId = this.currentActivePanel.id; + + if (newPanelId !== currentPanelId) { + const newTabId = newPanelId.split("_panel").shift(); + this.simulateClick(newTabId, newPanelId); + } + }); } simulateClick(tab, panel) { diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 3e550a0167..1660fc3da2 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -119,6 +119,15 @@ describe ' accept_alert do click_link "Primary Details" end + + # Back navigation loads the tab content + page.execute_script('window.history.back()') + expect(page).to have_selector '#enterprise_description' + + accept_alert do + click_link "Primary Details" + end + # Unchecking hides the Properties tab uncheck 'enterprise_is_primary_producer' choose 'None'