diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss
index cdc1684d3..5978296e2 100644
--- a/app/assets/stylesheets/admin.scss
+++ b/app/assets/stylesheets/admin.scss
@@ -235,4 +235,10 @@ label {
list-style: none;
padding: 0;
}
+ // override the Bootstrap collapse animation
+ .collapsing {
+ -webkit-transition: none;
+ transition: none;
+ display: none;
+ }
}
diff --git a/app/javascript/admin/__tests__/controllers/sidebar_controller.test.js b/app/javascript/admin/__tests__/controllers/sidebar_controller.test.js
index 1c3aaeedc..785a837c3 100644
--- a/app/javascript/admin/__tests__/controllers/sidebar_controller.test.js
+++ b/app/javascript/admin/__tests__/controllers/sidebar_controller.test.js
@@ -23,7 +23,7 @@ describe('SidebarController', () => {
Advanced
-
+
-
Broadcasts
@@ -104,18 +104,11 @@ describe('SidebarController', () => {
window.location = location;
});
- it('redirects to the first child navigation item', () => {
- const button = document.getElementById('advanced_button');
- button.click();
-
- expect(window.location.href).toEqual('/admin/advanced/broadcasts');
- });
-
it('closes other menu items', () => {
const button = document.getElementById('advanced_button');
button.click();
- expect(document.getElementById('apps').classList).toContain('hide');
+ expect(document.getElementById('apps').classList).not.toContain('show');
});
});
});
diff --git a/app/javascript/admin/controllers/sidebar_controller.js b/app/javascript/admin/controllers/sidebar_controller.js
index c4502c5d2..73e8aecbb 100644
--- a/app/javascript/admin/controllers/sidebar_controller.js
+++ b/app/javascript/admin/controllers/sidebar_controller.js
@@ -5,30 +5,26 @@ export default class SidebarController extends Controller {
static targets = ['submenu'];
disableCurrentNavItem() {
- const activeMenuId = this.submenuTargets.filter((item) =>
- item.classList.contains('show'),
- )[0].id;
- const activeButton = document.getElementById(`${activeMenuId}_button`);
- activeButton.setAttribute('disabled', true);
+ if (this.submenuTargets.length > 0) {
+ const activeMenuId = this.submenuTargets.filter((item) =>
+ item.classList.contains('show'),
+ )[0]?.id;
+
+ if (activeMenuId) {
+ const activeButton = document.getElementById(`${activeMenuId}_button`);
+ activeButton.setAttribute('disabled', true);
+ }
+ }
}
- expandDropdown(event) {
- this.redirectToFirstChildNavItem(event);
+ expandDropdown() {
this.closeOtherMenus();
}
- redirectToFirstChildNavItem(event) {
- window.location.href = event.target.getAttribute('data-target-href');
- }
-
closeOtherMenus() {
- const expandedList = ['expand', 'show'];
- const collapsedList = ['collapse', 'hide'];
-
this.submenuTargets.map((item) => {
if (item.classList.contains('show')) {
- item.classList.remove(...expandedList);
- item.classList.add(...collapsedList);
+ item.classList.remove('show');
}
});
}
diff --git a/app/views/admin/shared/_nested_sidebar.html.erb b/app/views/admin/shared/_nested_sidebar.html.erb
index 38512f4a0..84a44e9a3 100644
--- a/app/views/admin/shared/_nested_sidebar.html.erb
+++ b/app/views/admin/shared/_nested_sidebar.html.erb
@@ -15,7 +15,6 @@
id="<%= group_name %>_button"
data-toggle="collapse"
data-target="#<%= group_name %>"
- data-target-href="/admin/<%= group_name %>/<%= group[:children][0][:controller] %>"
aria-expanded="<%= (deduced_scope(request) == group_name.to_s).to_s %>"
aria-controls="<%= group_name %>"
data-action="click->sidebar#expandDropdown">
@@ -24,7 +23,8 @@
">
+ class="js-menu-activator <%= deduced_scope(request) == group_name.to_s ? "collapse show" : "collapse" %>"
+ data-target-href="/admin/<%= group_name %>/<%= group[:children][0][:controller] %>">
<% group[:children].each do |item| %>
<% if item[:visible] %>
-
@@ -40,3 +40,15 @@
<% end %>
<% end %>
+
+