Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Highlight active account menu links (#2462)
Leendert de Borsta9f4b746035d
diff --git a/apps/web/src/components/layout/TopMenu.tsx b/apps/web/src/components/layout/TopMenu.tsxindex a8ab93239..e52f59184 100644--- a/apps/web/src/components/layout/TopMenu.tsx+++ b/apps/web/src/components/layout/TopMenu.tsx@@ -23,8 +23,8 @@ import { useKeyboardShortcut } from '@/hooks/useKeyboardShortcut';/*** One link in the account menu.*/-const AccountMenuLink: React.FC<{ to: string; icon: SettingsIconName; label: string; onNavigate: () => void; children?: React.ReactNode }> = ({ to, icon, label, onNavigate, children }) => (- <MenuItem to={to} onClick={onNavigate} icon={<SettingsIcon name={icon} className="w-5 h-5" />} label={label}>{children}</MenuItem>+const AccountMenuLink: React.FC<{ to: string; icon: SettingsIconName; label: string; onNavigate: () => void; exact?: boolean; children?: React.ReactNode }> = ({ to, icon, label, onNavigate, exact, children }) => (+ <MenuItem to={to} exact={exact} onClick={onNavigate} icon={<SettingsIcon name={icon} className="w-5 h-5" />} label={label}>{children}</MenuItem>);/**@@ -144,7 +144,7 @@ const TopMenu: React.FC = () => {<AccountMenuLink onNavigate={closeUserMenu} to="/settings/apps" icon="apps" label={t('settings.apps.pageTitle')} /></div><div className="border-t border-gray-100 dark:border-gray-600 py-1">- <AccountMenuLink onNavigate={closeUserMenu} to="/settings" icon="general" label={t('common.settings')} />+ <AccountMenuLink onNavigate={closeUserMenu} to="/settings" exact icon="general" label={t('common.settings')} /></div><div className="border-t border-gray-100 dark:border-gray-600 pt-1"><DbLockButton />diff --git a/apps/web/src/components/shared/MenuItem.tsx b/apps/web/src/components/shared/MenuItem.tsxindex 6c7b625a0..deaad57d5 100644--- a/apps/web/src/components/shared/MenuItem.tsx+++ b/apps/web/src/components/shared/MenuItem.tsx@@ -8,27 +8,40 @@ type MenuItemProps = {onClick?: () => void;danger?: boolean;size?: 'sm' | 'md';+ exact?: boolean;id?: string;children?: React.ReactNode;};/**- * One row in a dropdown menu, as a link or a button.+ * One row in a dropdown menu, as a link or a button. A link to the current page is highlighted.*/-const MenuItem: React.FC<MenuItemProps> = ({ label, icon, to, onClick, danger = false, size = 'sm', id, children }) => {- const className = `flex items-center gap-3 w-full px-4 ${size === 'md' ? 'py-3' : 'py-2'} text-sm text-left transition-colors hover:bg-gray-100 dark:hover:bg-white/10 ${danger ? 'text-red-600 dark:text-red-400' : 'text-gray-700 dark:text-gray-200'}`;- const content = (+const MenuItem: React.FC<MenuItemProps> = ({ label, icon, to, onClick, danger = false, size = 'sm', exact = false, id, children }) => {+ /**+ * Classes including highlight active state.+ * @param isActive - whether the link's route is active+ */+ const rowClass = (isActive: boolean): string => {+ const tone = danger ? 'text-red-600 dark:text-red-400' : isActive ? 'text-primary-700 bg-primary-50 dark:text-primary-400 dark:bg-white/5' : 'text-gray-700 dark:text-gray-200';+ return `flex items-center gap-3 w-full px-4 ${size === 'md' ? 'py-3' : 'py-2'} text-sm text-left transition-colors hover:bg-gray-100 dark:hover:bg-white/10 ${tone}`;+ };++ /**+ * Inner content.+ * @param isActive - whether the link's route is active+ */+ const content = (isActive: boolean): React.ReactNode => (<>- {icon && <span className={`flex-shrink-0 ${danger ? 'text-red-600 dark:text-red-400' : 'text-gray-500 dark:text-gray-400'}`}>{icon}</span>}+ {icon && <span className={`flex-shrink-0 ${danger ? 'text-red-600 dark:text-red-400' : isActive ? 'text-primary-600 dark:text-primary-400' : 'text-gray-500 dark:text-gray-400'}`}>{icon}</span>}<span className="flex-1 min-w-0">{label}</span>{children}</>);return to ? (- <NavLink to={to} id={id} onClick={onClick} className={className}>{content}</NavLink>+ <NavLink to={to} end={exact} id={id} onClick={onClick} className={({ isActive }) => rowClass(isActive)}>{({ isActive }) => content(isActive)}</NavLink>) : (- <button type="button" id={id} onClick={onClick} className={className}>{content}</button>+ <button type="button" id={id} onClick={onClick} className={rowClass(false)}>{content(false)}</button>);};