Skip to content

Commit bf25e80

Browse files
committed
getMenuTooltip shows required roles from SITE_MAP if page is setup to
use.
1 parent e89aaca commit bf25e80

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/routes/+layout.svelte

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { Navigation } from "@skeletonlabs/skeleton-svelte";
44
import { page } from "$app/state";
55
import { navSections as allNavSections, type NavigationSection } from "$lib/config/navigation";
6+
import { SITE_MAP } from "$lib/utils/roleChecker";
67
78
// Separate My Account and Banks from other sections so they render in specific positions
89
const myAccountSection = allNavSections.find(s => s.id === "my-account");
@@ -146,6 +147,16 @@
146147
expandedSections[id] = !expandedSections[id];
147148
}
148149
150+
function getMenuTooltip(href: string, label: string): string {
151+
if (href.startsWith("http")) return label;
152+
const path = href.split("?")[0];
153+
const config = SITE_MAP[path];
154+
if (!config) return `${label}\n(Not in Site Map)`;
155+
const roles = config.required.map((r) => r.role);
156+
if (roles.length === 0) return `${label}\nRequired roles: (none)`;
157+
return `${label}\nRequired roles: ${roles.join(", ")}`;
158+
}
159+
149160
logger.info("🧭 Navigation state initialized");
150161
const navStateTime = performance.now();
151162
logger.info(
@@ -303,7 +314,7 @@
303314
class:border={page.url.pathname === item.href}
304315
class:border-solid-secondary-500={page.url.pathname ===
305316
item.href}
306-
title={item.label}
317+
title={getMenuTooltip(item.href, item.label)}
307318
aria-label={item.label}
308319
target={item.external ? "_blank" : undefined}
309320
rel={item.external ? "noopener noreferrer" : undefined}
@@ -349,7 +360,7 @@
349360
class:border-l-2={page.url.pathname === subItem.href}
350361
class:border-primary-500={page.url.pathname ===
351362
subItem.href}
352-
title={subItem.label}
363+
title={getMenuTooltip(subItem.href, subItem.label)}
353364
aria-label={subItem.label}
354365
target={subItem.external ? "_blank" : undefined}
355366
rel={subItem.external ? "noopener noreferrer" : undefined}
@@ -395,7 +406,7 @@
395406
class:preset-filled-primary-50-950={page.url.pathname === item.href}
396407
class:border={page.url.pathname === item.href}
397408
class:border-solid-secondary-500={page.url.pathname === item.href}
398-
title={item.label}
409+
title={getMenuTooltip(item.href, item.label)}
399410
aria-label={item.label}
400411
>
401412
<ItemIcon class="size-5" />
@@ -420,7 +431,7 @@
420431
class:border={page.url.pathname === item.href}
421432
class:border-solid-secondary-500={page.url.pathname ===
422433
item.href}
423-
title={item.label}
434+
title={getMenuTooltip(item.href, item.label)}
424435
aria-label={item.label}
425436
target={item.external ? "_blank" : undefined}
426437
rel={item.external ? "noopener noreferrer" : undefined}
@@ -467,7 +478,7 @@
467478
class:border-l-2={currentUrl === subItem.href}
468479
class:border-primary-500={currentUrl ===
469480
subItem.href}
470-
title={subItem.label}
481+
title={getMenuTooltip(subItem.href, subItem.label)}
471482
aria-label={subItem.label}
472483
target={subItem.external ? "_blank" : undefined}
473484
rel={subItem.external ? "noopener noreferrer" : undefined}

0 commit comments

Comments
 (0)