From 870755b5706475dac8882f338efa4cdb357e5491 Mon Sep 17 00:00:00 2001 From: hiep200311 Date: Fri, 5 Jun 2026 21:27:02 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20sidebar=20kh=C3=B4ng=20ho=E1=BA=A1t=20?= =?UTF-8?q?=C4=91=E1=BB=99ng=20khi=20click=20n=C3=BAt=20menu=20tr=C3=AAn?= =?UTF-8?q?=20mobile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lỗi: sidebar.js dùng DOMContentLoaded nhưng script được load động sau khi sự kiện này đã kích hoạt → initSidebar() không bao giờ chạy → nút menu không có event listener → click không phản hồi. Sửa: gọi initSidebar() trực tiếp thay vì bọc trong DOMContentLoaded. --- views/components/sidebar/sidebar.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/views/components/sidebar/sidebar.js b/views/components/sidebar/sidebar.js index 159e12f..6eda3f0 100644 --- a/views/components/sidebar/sidebar.js +++ b/views/components/sidebar/sidebar.js @@ -1,7 +1,8 @@ // views/components/sidebar/sidebar.js -document.addEventListener("DOMContentLoaded", () => { - initSidebar(); -}); +// NOTE: This script is always loaded dynamically by sidebarLoader.js AFTER +// the sidebar HTML has already been injected into #sidebar-container. +// DOMContentLoaded has already fired at this point, so we must call +// initSidebar() directly — NOT inside a DOMContentLoaded listener. function initSidebar() { const floatingMenuBtn = document.getElementById("floatingMenuBtn"); @@ -67,3 +68,6 @@ function initSidebar() { lastScrollY = window.scrollY; }); } + +// Call directly — sidebar HTML is already in DOM when this script executes +initSidebar();