Skip to content

Commit

Permalink
fix: Prevent multiple dropdowns opening at once (openedx#33046)
Browse files Browse the repository at this point in the history
This closes already open dropdown menus when opening another dropdown
menu, to prevent them from overlapping each other.
  • Loading branch information
yusuf-musleh authored Aug 17, 2023
1 parent ddb092c commit 6b22286
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cms/static/js/views/course_outline.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,15 @@ function(
showActionsMenu(event) {
const showActionsButton = event.currentTarget;
const subMenu = showActionsButton.parentElement.querySelector(".wrapper-nav-sub");

// Close all open dropdowns
const elements = document.querySelectorAll("li.action-item.action-actions-menu.nav-item");
elements.forEach(element => {
if (element !== showActionsButton.parentElement) {
element.querySelector('.wrapper-nav-sub').classList.remove('is-shown');
}
});

// Code in 'base.js' normally handles toggling these dropdowns but since this one is
// not present yet during the domReady event, we have to handle displaying it ourselves.
subMenu.classList.toggle("is-shown");
Expand Down Expand Up @@ -452,7 +461,7 @@ function(
event.preventDefault();
this.pasteUnit(event);
});
element.find('.action-actions-menu').click((event) => {
element.find('.show-actions-menu-button').click((event) => {
this.showActionsMenu(event);
});
},
Expand Down
9 changes: 9 additions & 0 deletions cms/static/js/views/pages/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,15 @@ function($, _, Backbone, gettext, BasePage, ViewUtils, ContainerView, XBlockView
showXBlockActionsMenu: function(event) {
const showActionsButton = event.currentTarget;
const subMenu = showActionsButton.parentElement.querySelector('.wrapper-nav-sub');

// Close all open dropdowns
const elements = document.querySelectorAll("li.action-item.action-actions-menu.nav-item");
elements.forEach(element => {
if (element !== showActionsButton.parentElement) {
element.querySelector('.wrapper-nav-sub').classList.remove('is-shown');
}
});

// Code in 'base.js' normally handles toggling these dropdowns but since this one is
// not present yet during the domReady event, we have to handle displaying it ourselves.
subMenu.classList.toggle('is-shown');
Expand Down

0 comments on commit 6b22286

Please sign in to comment.