Skip to content

Commit

Permalink
fix(navbar): submenus not properly closing on mobile
Browse files Browse the repository at this point in the history
Instead of properly closing the submenus on mobile, they would shift left and
still be usable. This has been addressed by improved element targeting and the
inclusion of the `touchstart` event.
  • Loading branch information
tomudding committed Dec 25, 2024
1 parent 1f830c2 commit 040f390
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions public/js/navbar.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Handle submenus
$('li.dropdown-submenu [data-toggle=dropdown]').on('click', function(event) {
$('li.dropdown-submenu > [data-toggle=dropdown]').on('click touchstart', function(event) {
event.preventDefault();
event.stopPropagation();

var parent = $(this).parent();

// Also update aria-expanded for accessibility purposes.
if ($(this).parent().hasClass('open')) {
$(this).parent().removeClass('open');
if (parent.hasClass('open')) {
parent.removeClass('open');
$(this).attr('aria-expanded', 'false');
} else {
$(this).parent().addClass('open');
parent.addClass('open');
$(this).attr('aria-expanded', 'true');
}
});
Expand Down

0 comments on commit 040f390

Please sign in to comment.