From 040f3903b33c692bb06c58a18a7f23ae5eb79572 Mon Sep 17 00:00:00 2001 From: Tom Udding Date: Wed, 25 Dec 2024 16:13:53 +0100 Subject: [PATCH] fix(navbar): submenus not properly closing on mobile 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. --- public/js/navbar.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/js/navbar.js b/public/js/navbar.js index 5616ad1ad9..b0f3c84390 100644 --- a/public/js/navbar.js +++ b/public/js/navbar.js @@ -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'); } });