From 7fbdbcb5970a78d14d54398ffcddb28025c06f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gestor=C3=ADa=20LP?= Date: Mon, 2 Mar 2026 04:11:59 +0000 Subject: [PATCH] fix: dropdown service links not working from navbar The smooth scroll handler was intercepting clicks on the "Servicios" dropdown toggle link (href="#servicios"), which on the landing page would find the #servicios section and call closeMenu(), immediately closing the menu before the user could click any service link. Fix: skip dropdown toggle links in smooth scroll handler, make dropdown toggle work via click on all devices (not just CSS :hover). Co-Authored-By: Claude Opus 4.6 --- assets/css/style.css | 3 ++- assets/js/main.js | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/assets/css/style.css b/assets/css/style.css index 5e7fe61..38f280f 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -407,7 +407,8 @@ p:last-child { transform: translateY(0); } -.navbar__item--dropdown:hover .navbar__link--dropdown i { +.navbar__item--dropdown:hover .navbar__link--dropdown i, +.navbar__item--dropdown.active .navbar__link--dropdown i { transform: rotate(180deg); } diff --git a/assets/js/main.js b/assets/js/main.js index d152b9c..9b569ae 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -56,27 +56,38 @@ document.addEventListener('DOMContentLoaded', function () { }); // ================================================================ - // 2. Mobile Dropdown Toggle + // 2. Dropdown Toggle (mobile + touch devices) // ================================================================ var dropdownItems = document.querySelectorAll('.navbar__item--dropdown'); dropdownItems.forEach(function (item) { var link = item.querySelector('.navbar__link--dropdown'); if (link) { link.addEventListener('click', function (e) { - // Only toggle on mobile - if (window.innerWidth <= 768) { - e.preventDefault(); - item.classList.toggle('active'); - } + // Always prevent default on the dropdown parent link + e.preventDefault(); + e.stopPropagation(); + item.classList.toggle('active'); }); } }); + // Close dropdown when clicking outside (desktop) + document.addEventListener('click', function (e) { + dropdownItems.forEach(function (item) { + if (!item.contains(e.target)) { + item.classList.remove('active'); + } + }); + }); + // ================================================================ // 3. Smooth Scroll for Anchor Links // ================================================================ var anchorLinks = document.querySelectorAll('a[href^="#"]'); anchorLinks.forEach(function (link) { + // Skip dropdown toggle links — they have their own handler + if (link.classList.contains('navbar__link--dropdown')) return; + link.addEventListener('click', function (e) { var targetId = this.getAttribute('href'); if (targetId === '#') return;