|
60 | 60 | }, |
61 | 61 | ], |
62 | 62 | }, |
| 63 | + { |
| 64 | + label: "Dynamic Endpoints", |
| 65 | + icon: "🔌", |
| 66 | + available: true, |
| 67 | + subItems: [ |
| 68 | + { |
| 69 | + href: "/dynamic-endpoints/system", |
| 70 | + label: "System Dynamic Endpoints", |
| 71 | + icon: "⚙️", |
| 72 | + }, |
| 73 | + { |
| 74 | + href: "/dynamic-endpoints/bank", |
| 75 | + label: "Bank Dynamic Endpoints", |
| 76 | + icon: "🏦", |
| 77 | + }, |
| 78 | + ], |
| 79 | + }, |
63 | 80 | ].filter((item) => item.available) |
64 | 81 | : [], |
65 | 82 | ); |
66 | 83 |
|
67 | 84 | // Reactive check for active route |
68 | | - function isActiveRoute(href: string): boolean { |
| 85 | + function isActiveRoute(href: string | undefined): boolean { |
| 86 | + if (!href) return false; |
69 | 87 | if (href === "/") { |
70 | 88 | return $page.url.pathname === "/"; |
71 | 89 | } |
72 | 90 | return $page.url.pathname.startsWith(href); |
73 | 91 | } |
74 | 92 |
|
| 93 | + // Check if any sub-item of a dropdown is active |
| 94 | + function isDropdownActive(subItems: Array<{ href: string }> | undefined): boolean { |
| 95 | + if (!subItems) return false; |
| 96 | + return subItems.some((subItem) => isActiveRoute(subItem.href)); |
| 97 | + } |
| 98 | +
|
75 | 99 | // Event handlers with better encapsulation |
76 | 100 | const handlers = { |
77 | 101 | toggleMobileMenu: () => { |
|
135 | 159 | <div class="nav-dropdown"> |
136 | 160 | <button |
137 | 161 | class="nav-link dropdown-toggle" |
138 | | - class:active={isActiveRoute(item.href)} |
| 162 | + class:active={isDropdownActive(item.subItems)} |
139 | 163 | onclick={() => handlers.toggleDropdown(item.label)} |
140 | 164 | onblur={() => setTimeout(handlers.closeDropdown, 200)} |
141 | 165 | > |
|
239 | 263 | <div class="mobile-nav-dropdown"> |
240 | 264 | <button |
241 | 265 | class="mobile-nav-link" |
242 | | - class:active={isActiveRoute(item.href)} |
| 266 | + class:active={isDropdownActive(item.subItems)} |
243 | 267 | onclick={() => handlers.toggleDropdown(item.label)} |
244 | 268 | > |
245 | 269 | <span class="nav-icon">{item.icon}</span> |
|
0 commit comments