import React from 'react'; import { Link, useLocation } from 'react-router-dom'; import type { SubItem } from '@/nav/tree'; type Props = { items?: SubItem[] }; export default function SubmenuBar({ items = [] }: Props) { // Always call hooks first const { pathname } = useLocation(); // Single source of truth: props.items. No fallbacks, no demos, no path-based defaults if (items.length === 0) return null; return (
{items.map((it) => { const key = `${it.label}-${it.path || it.href}`; // Fix: Always use exact match to prevent first submenu from being always active const isActive = !!it.path && pathname === it.path; const cls = [ 'inline-flex items-center gap-2 rounded-md px-2.5 py-1.5 border text-sm whitespace-nowrap', 'focus:outline-none focus:ring-0 focus:shadow-none', isActive ? 'bg-accent text-accent-foreground' : 'hover:bg-accent hover:text-accent-foreground', ].join(' '); if (it.mode === 'spa' && it.path) { return ( {it.label} ); } if (it.mode === 'bridge' && it.href) { return ( {it.label} ); } return null; })}
); }