Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
fix(frontend): promote mobile platform switching
rcourtman7879862c24a9
diff --git a/docs/release-control/v6/internal/subsystems/frontend-primitives.md b/docs/release-control/v6/internal/subsystems/frontend-primitives.mdindex b60d355839..b10abdc3f6 100644--- a/docs/release-control/v6/internal/subsystems/frontend-primitives.md+++ b/docs/release-control/v6/internal/subsystems/frontend-primitives.md@@ -4055,20 +4055,24 @@ lookups or DOM listener lifecycle back into the shared shell.The shared mobile nav now follows that same owner split.`frontend-modern/src/components/shared/MobileNavBar.tsx` stays the rendershell, `frontend-modern/src/components/shared/useMobileNavBarState.ts` owns-fade signals, scroll and resize listeners, active-tab centering, and click-handoff lifecycle, and+the mutually exclusive platform/overflow menu state, keyboard focus return,+outside-click dismissal, last-active-platform continuity, and click handoff+lifecycle, and`frontend-modern/src/components/shared/mobileNavBarModel.ts` owns platform and-utility tab ordering, alert badge counts, fade-state derivation, and tab+utility tab ordering, the dedicated platform-switcher projection, alert badge+counts, and tabbutton class policy. Future mobile-nav work should extend those owners insteadof pushing tab-order or DOM lifecycle logic back into the shared shell. Withsupport/admin controls moved under Settings, that utility ordering must no longerreserve a standalone `operations` slot; alerts, Patrol, and Settings are theremaining authenticated utility tabs.-The platform rail is the only horizontally scrolling region in that shell.-Alerts, Patrol, and Settings stay pinned in a separate utility rail so primary-platform breadth cannot push those global destinations beyond the phone-viewport, while active-platform centering and fade state remain scoped to the-primary rail.+Platform switching is a first-level mobile action. The first bottom-rail slot+must show the current or most recently active platform and open the dedicated+platform menu containing every evidence-admitted platform; platform choices+must not be buried in the generic More menu. Alerts, Patrol, and Actions remain+pinned daily-operation destinations. More is reserved for secondary utilities+such as Settings, keeping the bottom rail to five predictable targets without+making infrastructure switching a two-level navigation task.The shared command palette now follows that same owner split.`frontend-modern/src/components/shared/CommandPaletteModal.tsx` stays therender shell, `frontend-modern/src/components/shared/useCommandPaletteState.ts`diff --git a/frontend-modern/browser-verification.json b/frontend-modern/browser-verification.jsonindex 68001202a2..b2f3baa4f0 100644--- a/frontend-modern/browser-verification.json+++ b/frontend-modern/browser-verification.json@@ -1,39 +1,45 @@{"version": 1,"result": "passed",- "verified_at": "2026-08-18T19:01:00Z",- "base_sha": "9bec2a52b518ac6164652574962ea078d82df330",+ "verified_at": "2026-08-18T19:14:48Z",+ "base_sha": "4be10526b653815389996d3d0e99fe582c648dc0","changed_paths": [- "frontend-modern/src/features/alerts/AlertDeliveryPausedCard.tsx",- "frontend-modern/src/features/alerts/tabs/DestinationsTab.tsx",- "frontend-modern/src/utils/alertDestinationsPresentation.ts"+ "frontend-modern/src/components/shared/MobileNavBar.tsx",+ "frontend-modern/src/components/shared/mobileNavBarModel.ts",+ "frontend-modern/src/components/shared/useMobileNavBarState.ts"],"content_sha256": {- "frontend-modern/src/features/alerts/AlertDeliveryPausedCard.tsx": "24ba381b7ee24247c53707d2fb5e311d8add2a43b8ba30bd1780e5bbf66d539b",- "frontend-modern/src/features/alerts/tabs/DestinationsTab.tsx": "8f448e48aef2bf10286a8c175a6091e9706dcf9990b6fb9ccc2651f6dbbd7acf",- "frontend-modern/src/utils/alertDestinationsPresentation.ts": "40432ae601f5916d957113aa33c2c4597eaf1ea014e2bf1a90b5e91f275992c5"+ "frontend-modern/src/components/shared/MobileNavBar.tsx": "94d38c6497660a31c2d9ea2ab8b7b1fcf07c58402b4b75f638753e028b665f38",+ "frontend-modern/src/components/shared/mobileNavBarModel.ts": "f1ef527cb91657d748e26ed37dfa9d1b8527469837cd1838d5f41c53b13ea5db",+ "frontend-modern/src/components/shared/useMobileNavBarState.ts": "b9f7d406e7c7d11c1c4d9c6655e13c4abf3cc2c1b1f6f55808dafa77b36b31ce"},"routes": [- "/alerts/notifications",- "/alerts/overview"- ],- "states": [- "activationState=pending_review: paused card renders above the Email notifications section",- "activationState=active: paused card is absent",- "alert config not yet loaded: no card rendered, so no false warning flash on tab open"- ],- "interactions": [- "clicked 'Turn on delivery' on /alerts/notifications; card cleared and the overview header moved to 'Notifications enabled'",- "restored activation via the overview toggle; card returned and the backend reported pending_review again"+ "/proxmox/overview",+ "/proxmox/replication",+ "/docker/overview"],"viewports": [{- "width": 1280,- "height": 800+ "width": 1440,+ "height": 1000},{- "width": 375,- "height": 812+ "width": 390,+ "height": 844}+ ],+ "states": [+ "Mobile bottom navigation with Proxmox active and the dedicated platform switcher closed",+ "Platform switcher open with Proxmox, Docker, Kubernetes, TrueNAS, vSphere, and Machines visible",+ "Docker active after direct selection from the platform switcher",+ "More menu open with Settings as its only secondary utility",+ "Desktop primary navigation visible with the mobile bottom navigation hidden"+ ],+ "interactions": [+ "opened the first-slot platform switcher from Proxmox",+ "selected Docker and verified navigation to /docker/overview plus the current-platform label",+ "opened More and verified that no platform destinations remain in its utility menu",+ "selected Proxmox from the platform switcher",+ "exercised ArrowDown, arrow traversal, Home, End, Escape focus return, and outside-click dismissal in component tests"]}diff --git a/frontend-modern/src/__tests__/AppLayout.test.tsx b/frontend-modern/src/__tests__/AppLayout.test.tsxindex ac3dfffe82..a1d0d62a12 100644--- a/frontend-modern/src/__tests__/AppLayout.test.tsx+++ b/frontend-modern/src/__tests__/AppLayout.test.tsx@@ -293,6 +293,17 @@ describe('AppLayout navigation icons', () => {expect(within(infrastructureGroup as HTMLElement).getByRole('tab', { name: 'vSphere' }),).toBeTruthy();++ const mobileNav = screen.getByRole('navigation', { name: 'Mobile navigation' });+ fireEvent.click(+ within(mobileNav).getByRole('button', { name: 'Switch platform, current Proxmox' }),+ );+ const platformMenu = screen.getByRole('menu', { name: 'Switch platform' });+ expect(+ within(platformMenu)+ .getAllByRole('menuitem')+ .map((item) => item.getAttribute('data-tab-id')),+ ).toEqual(['proxmox', 'docker', 'vmware', 'standalone']);});it('does not expose cached platform evidence before navigation admission resolves', () => {diff --git a/frontend-modern/src/components/shared/MobileNavBar.tsx b/frontend-modern/src/components/shared/MobileNavBar.tsxindex 27f9f9bcc8..d52117affa 100644--- a/frontend-modern/src/components/shared/MobileNavBar.tsx+++ b/frontend-modern/src/components/shared/MobileNavBar.tsx@@ -1,4 +1,5 @@import { For, Show } from 'solid-js';+import ChevronsUpDownIcon from 'lucide-solid/icons/chevrons-up-down';import EllipsisIcon from 'lucide-solid/icons/ellipsis';import { type MobileNavBarProps, useMobileNavBarState } from './useMobileNavBarState';import {@@ -18,6 +19,7 @@ export type {} from './mobileNavBarModel';const MOBILE_NAV_OVERFLOW_ID = 'mobile-navigation-overflow';+const MOBILE_NAV_PLATFORM_SWITCHER_ID = 'mobile-navigation-platform-switcher';function MobileNavDestinationContent(props: {destination: MobileNavBarDestination;@@ -158,10 +160,6 @@ export function MobileNavBar(props: MobileNavBarProps) {onKeyDown={mobileNav.handleOverflowMenuKeyDown}class="absolute inset-x-2 bottom-full mb-2 max-h-[70vh] overflow-y-auto rounded-lg border border-border bg-surface p-1 shadow-xl">- {renderOverflowGroup({- label: 'Infrastructure',- destinations: mobileNav.overflowPrimaryDestinations,- })}{renderOverflowGroup({label: 'Pulse',destinations: mobileNav.overflowUtilityDestinations,@@ -169,7 +167,61 @@ export function MobileNavBar(props: MobileNavBarProps) {</div></Show>+ <Show when={mobileNav.isPlatformMenuOpen()}>+ <div+ id={MOBILE_NAV_PLATFORM_SWITCHER_ID}+ ref={mobileNav.setPlatformMenuRef}+ role="menu"+ aria-label="Switch platform"+ onKeyDown={mobileNav.handlePlatformMenuKeyDown}+ class="absolute inset-x-2 bottom-full mb-2 max-h-[70vh] overflow-y-auto rounded-lg border border-border bg-surface p-1 shadow-xl"+ >+ {renderOverflowGroup({+ label: 'Infrastructure',+ destinations: mobileNav.platformDestinations,+ })}+ </div>+ </Show>+<div data-mobile-nav-rail="fixed" class="flex min-w-0 items-stretch gap-0.5 px-0.5 py-0.5">+ <Show when={mobileNav.activePlatformDestination()}>+ {(destination) => {+ const canSwitch = () => mobileNav.platformDestinations().length > 1;+ const currentLabel = () => destination().tab.label;++ return (+ <button+ ref={mobileNav.setPlatformTriggerRef}+ type="button"+ data-tab-id="platform-switcher"+ data-mobile-nav-destination="platform-switcher"+ aria-label={+ canSwitch() ? `Switch platform, current ${currentLabel()}` : currentLabel()+ }+ aria-haspopup={canSwitch() ? 'menu' : undefined}+ aria-expanded={canSwitch() ? mobileNav.isPlatformMenuOpen() : undefined}+ aria-controls={canSwitch() ? MOBILE_NAV_PLATFORM_SWITCHER_ID : undefined}+ aria-current={mobileNav.platformIsActive() ? 'page' : undefined}+ onClick={mobileNav.handlePlatformTriggerClick}+ onKeyDown={mobileNav.handlePlatformTriggerKeyDown}+ title={canSwitch() ? 'Switch platform' : destination().tab.tooltip}+ class={getMobileNavTabButtonClass({+ active: mobileNav.platformIsActive(),+ enabled: destination().tab.enabled,+ })}+ >+ <MobileNavDestinationContent destination={destination()} iconClass={tabIconClass} />+ <Show when={canSwitch()}>+ <ChevronsUpDownIcon+ aria-hidden="true"+ class="absolute right-1 top-1 h-2.5 w-2.5 text-muted"+ />+ </Show>+ </button>+ );+ }}+ </Show>+<For each={mobileNav.fixedDestinations()}>{(destination) => {const active = () => isMobileNavDestinationActive(destination, props.activeTab());diff --git a/frontend-modern/src/components/shared/__tests__/MobileNavBar.test.tsx b/frontend-modern/src/components/shared/__tests__/MobileNavBar.test.tsxindex 712a6bcbcc..f653c6a1e4 100644--- a/frontend-modern/src/components/shared/__tests__/MobileNavBar.test.tsx+++ b/frontend-modern/src/components/shared/__tests__/MobileNavBar.test.tsx@@ -85,7 +85,7 @@ describe('MobileNavBar', () => {expect(mobileNavBarModelSource).not.toContain("'recovery'");});- it('renders one platform and the daily operations set with every other route in More', async () => {+ it('renders a dedicated platform switcher and keeps More for secondary utilities', async () => {const { container } = render(() => (<MobileNavBaractiveTab={() => 'standalone'}@@ -112,30 +112,44 @@ describe('MobileNavBar', () => {Array.from(fixedRail?.querySelectorAll('button[data-tab-id]') ?? []).map((button) =>button.getAttribute('data-tab-id'),),- ).toEqual(['proxmox', 'alerts', 'ai', 'actions', 'more']);+ ).toEqual(['platform-switcher', 'alerts', 'ai', 'actions', 'more']);++ const platformSwitcher = screen.getByRole('button', {+ name: 'Switch platform, current Machines',+ });+ expect(platformSwitcher).toHaveAttribute('aria-haspopup', 'menu');+ expect(platformSwitcher).toHaveAttribute('aria-expanded', 'false');+ expect(platformSwitcher).toHaveAttribute('aria-current', 'page');+ fireEvent.click(platformSwitcher);++ const platformMenu = await screen.findByRole('menu', { name: 'Switch platform' });+ expect(platformSwitcher).toHaveAttribute('aria-expanded', 'true');+ expect(+ within(platformMenu)+ .getAllByRole('menuitem')+ .map((item) => item.getAttribute('data-tab-id')),+ ).toEqual(['proxmox', 'standalone']);+ expect(within(platformMenu).getByRole('menuitem', { name: 'Machines' })).toHaveAttribute(+ 'aria-current',+ 'page',+ );const more = screen.getByRole('button', { name: 'More navigation' });expect(more).toHaveAttribute('aria-haspopup', 'menu');expect(more).toHaveAttribute('aria-expanded', 'false');- expect(more).toHaveAttribute('aria-current', 'page');fireEvent.click(more);const menu = await screen.findByRole('menu', { name: 'More navigation destinations' });expect(more).toHaveAttribute('aria-expanded', 'true');- expect(within(menu).getByRole('group', { name: 'Infrastructure' })).toBeInTheDocument();+ expect(within(menu).queryByRole('group', { name: 'Infrastructure' })).toBeNull();expect(within(menu).getByRole('group', { name: 'Pulse' })).toBeInTheDocument();expect(within(menu).getAllByRole('menuitem').map((item) => item.getAttribute('data-tab-id')),- ).toEqual(['standalone', 'settings']);- expect(within(menu).getByRole('menuitem', { name: 'Machines' })).toHaveAttribute(- 'aria-current',- 'page',- );+ ).toEqual(['settings']);- const fixedProxmox = fixedRail?.querySelector('[data-tab-id="proxmox"]');- expect(fixedProxmox).toHaveClass('min-h-10', 'gap-0', 'py-0.5', 'text-[9px]');+ expect(platformSwitcher).toHaveClass('min-h-10', 'gap-0', 'py-0.5', 'text-[9px]');});it('preserves route callbacks for fixed and overflow destinations', async () => {@@ -159,15 +173,18 @@ describe('MobileNavBar', () => {expect.objectContaining({ id: 'alerts', route: '/alerts' }),);- const more = screen.getByRole('button', { name: 'More navigation' });- fireEvent.click(more);- const menu = await screen.findByRole('menu');- fireEvent.click(within(menu).getByRole('menuitem', { name: 'Machines' }));+ const platformSwitcher = screen.getByRole('button', {+ name: 'Switch platform, current Proxmox',+ });+ fireEvent.click(platformSwitcher);+ const platformMenu = await screen.findByRole('menu', { name: 'Switch platform' });+ fireEvent.click(within(platformMenu).getByRole('menuitem', { name: 'Machines' }));expect(onPrimaryClick).toHaveBeenCalledWith(expect.objectContaining({ id: 'standalone', route: '/standalone/overview' }),);expect(screen.queryByRole('menu')).toBeNull();+ const more = screen.getByRole('button', { name: 'More navigation' });fireEvent.click(more);fireEvent.click(await screen.findByRole('menuitem', { name: 'Settings' }));expect(onUtilityClick).toHaveBeenCalledWith(@@ -205,12 +222,16 @@ describe('MobileNavBar', () => {).toHaveTextContent('Patrol2');expect(within(nav).queryByRole('button', { name: 'Pulse Patrol Patrol' })).toBeNull();- fireEvent.click(within(nav).getByRole('button', { name: 'More navigation' }));- const menu = await screen.findByRole('menu');+ fireEvent.click(within(nav).getByRole('button', { name: 'Switch platform, current Proxmox' }));+ const menu = await screen.findByRole('menu', { name: 'Switch platform' });expect(within(menu).getByRole('menuitem', { name: /Machines/ })).toHaveTextContent('MachinesSetup',);- expect(within(menu).getByRole('menuitem', { name: 'Settings' })).toBeInTheDocument();+ fireEvent.click(within(nav).getByRole('button', { name: 'More navigation' }));+ const utilityMenu = await screen.findByRole('menu', {+ name: 'More navigation destinations',+ });+ expect(within(utilityMenu).getByRole('menuitem', { name: 'Settings' })).toBeInTheDocument();});it('supports menu arrow keys, Escape focus return, and outside dismissal', async () => {@@ -227,10 +248,12 @@ describe('MobileNavBar', () => {/>));- const more = screen.getByRole('button', { name: 'More navigation' });- more.focus();- fireEvent.keyDown(more, { key: 'ArrowDown' });- const menu = await screen.findByRole('menu');+ const platformSwitcher = screen.getByRole('button', {+ name: 'Switch platform, current Proxmox',+ });+ platformSwitcher.focus();+ fireEvent.keyDown(platformSwitcher, { key: 'ArrowDown' });+ const menu = await screen.findByRole('menu', { name: 'Switch platform' });const items = within(menu).getAllByRole('menuitem');await waitFor(() => expect(items[0]).toHaveFocus());@@ -242,10 +265,11 @@ describe('MobileNavBar', () => {expect(items[1]).toHaveFocus();fireEvent.keyDown(items[1], { key: 'Escape' });await waitFor(() => expect(screen.queryByRole('menu')).toBeNull());- expect(more).toHaveFocus();+ expect(platformSwitcher).toHaveFocus();+ const more = screen.getByRole('button', { name: 'More navigation' });fireEvent.click(more);- await screen.findByRole('menu');+ await screen.findByRole('menu', { name: 'More navigation destinations' });fireEvent.pointerDown(document.body);await waitFor(() => expect(screen.queryByRole('menu')).toBeNull());});diff --git a/frontend-modern/src/components/shared/__tests__/mobileNavBarModel.branchcov0712.test.ts b/frontend-modern/src/components/shared/__tests__/mobileNavBarModel.branchcov0712.test.tsindex 9de1cfe75e..4bab29c59c 100644--- a/frontend-modern/src/components/shared/__tests__/mobileNavBarModel.branchcov0712.test.ts+++ b/frontend-modern/src/components/shared/__tests__/mobileNavBarModel.branchcov0712.test.ts@@ -219,7 +219,7 @@ describe('mobileNavBarModel.branchcov2', () => {});describe('buildMobileNavBarLayout', () => {- it('keeps one priority-ordered platform and daily operations fixed', () => {+ it('keeps platforms in a dedicated switcher and daily operations fixed', () => {const layout = buildMobileNavBarLayout([makePrimaryTab('standalone'), makePrimaryTab('docker'), makePrimaryTab('proxmox')],[@@ -230,20 +230,20 @@ describe('mobileNavBarModel.branchcov2', () => {],);- expect(layout.fixedDestinations.map((destination) => destination.tab.id)).toEqual([+ expect(layout.platformDestinations.map((destination) => destination.tab.id)).toEqual(['proxmox',+ 'docker',+ 'standalone',+ ]);+ expect(layout.fixedDestinations.map((destination) => destination.tab.id)).toEqual(['alerts','ai','actions',]);expect(layout.overflowDestinations.map((destination) => destination.tab.id)).toEqual([- 'docker',- 'standalone','settings',]);expect(layout.overflowDestinations.map((destination) => destination.kind)).toEqual([- 'primary',- 'primary','utility',]);});@@ -254,8 +254,10 @@ describe('mobileNavBarModel.branchcov2', () => {[makeUtilityTab({ id: 'alerts' }), makeUtilityTab({ id: 'ai' })],);- expect(layout.fixedDestinations.map((destination) => destination.tab.id)).toEqual([+ expect(layout.platformDestinations.map((destination) => destination.tab.id)).toEqual(['proxmox',+ ]);+ expect(layout.fixedDestinations.map((destination) => destination.tab.id)).toEqual(['alerts','ai',]);diff --git a/frontend-modern/src/components/shared/mobileNavBarModel.ts b/frontend-modern/src/components/shared/mobileNavBarModel.tsindex effc3adee4..ec00dcba05 100644--- a/frontend-modern/src/components/shared/mobileNavBarModel.ts+++ b/frontend-modern/src/components/shared/mobileNavBarModel.ts@@ -35,11 +35,13 @@ export type MobileNavBarProps = {onUtilityClick: (tab: MobileNavBarUtilityTab) => void;};+export type MobileNavBarPrimaryDestination = { kind: 'primary'; tab: MobileNavBarPrimaryTab };+export type MobileNavBarUtilityDestination = { kind: 'utility'; tab: MobileNavBarUtilityTab };export type MobileNavBarDestination =- | { kind: 'primary'; tab: MobileNavBarPrimaryTab }- | { kind: 'utility'; tab: MobileNavBarUtilityTab };+ MobileNavBarPrimaryDestination | MobileNavBarUtilityDestination;export type MobileNavBarLayout = {+ platformDestinations: MobileNavBarPrimaryDestination[];fixedDestinations: MobileNavBarDestination[];overflowDestinations: MobileNavBarDestination[];};@@ -93,9 +95,10 @@ export function buildOrderedMobileNavUtilityTabs(}/**- * Keep the bottom bar to five predictable targets at most: the primary- * infrastructure destination, the three daily operations destinations, and- * More. Every other admitted platform and utility remains available in More.+ * Keep the bottom bar to five predictable targets at most: a dedicated+ * platform switcher, the three daily operations destinations, and More for+ * secondary utilities. Platform choice is primary navigation and must never+ * be buried in the generic overflow menu.*/export function buildMobileNavBarLayout(primaryTabs: MobileNavBarPrimaryTab[],@@ -103,24 +106,22 @@ export function buildMobileNavBarLayout(): MobileNavBarLayout {const orderedPrimaryTabs = buildOrderedMobileNavPrimaryTabs(primaryTabs);const orderedUtilityTabs = buildOrderedMobileNavUtilityTabs(utilityTabs);- const fixedPrimaryTabs = orderedPrimaryTabs.slice(0, 1);const fixedUtilityTabs = orderedUtilityTabs.filter((tab) =>MOBILE_NAV_FIXED_UTILITY_IDS.has(tab.id),);return {- fixedDestinations: [- ...fixedPrimaryTabs.map((tab): MobileNavBarDestination => ({ kind: 'primary', tab })),- ...fixedUtilityTabs.map((tab): MobileNavBarDestination => ({ kind: 'utility', tab })),- ],- overflowDestinations: [- ...orderedPrimaryTabs- .slice(1)- .map((tab): MobileNavBarDestination => ({ kind: 'primary', tab })),- ...orderedUtilityTabs- .filter((tab) => !MOBILE_NAV_FIXED_UTILITY_IDS.has(tab.id))- .map((tab): MobileNavBarDestination => ({ kind: 'utility', tab })),- ],+ platformDestinations: orderedPrimaryTabs.map((tab): MobileNavBarPrimaryDestination => ({+ kind: 'primary',+ tab,+ })),+ fixedDestinations: fixedUtilityTabs.map((tab): MobileNavBarDestination => ({+ kind: 'utility',+ tab,+ })),+ overflowDestinations: orderedUtilityTabs+ .filter((tab) => !MOBILE_NAV_FIXED_UTILITY_IDS.has(tab.id))+ .map((tab): MobileNavBarDestination => ({ kind: 'utility', tab })),};}diff --git a/frontend-modern/src/components/shared/useMobileNavBarState.ts b/frontend-modern/src/components/shared/useMobileNavBarState.tsindex 89270d15ab..0fe5929a32 100644--- a/frontend-modern/src/components/shared/useMobileNavBarState.ts+++ b/frontend-modern/src/components/shared/useMobileNavBarState.ts@@ -15,21 +15,19 @@ export type {} from './mobileNavBarModel';export function useMobileNavBarState(props: MobileNavBarProps) {- const [isOverflowOpen, setIsOverflowOpen] = createSignal(false);+ const [openMenu, setOpenMenu] = createSignal<'platform' | 'overflow' | null>(null);+ const [lastPrimaryTabId, setLastPrimaryTabId] = createSignal<string | null>(null);+ const [platformTriggerRef, setPlatformTriggerRef] = createSignal<HTMLButtonElement>();+ const [platformMenuRef, setPlatformMenuRef] = createSignal<HTMLDivElement>();const [overflowTriggerRef, setOverflowTriggerRef] = createSignal<HTMLButtonElement>();const [overflowMenuRef, setOverflowMenuRef] = createSignal<HTMLDivElement>();const layout = createMemo(() =>buildMobileNavBarLayout(props.primaryTabs(), props.utilityTabs()),);+ const platformDestinations = createMemo(() => layout().platformDestinations);const fixedDestinations = createMemo(() => layout().fixedDestinations);const overflowDestinations = createMemo(() => layout().overflowDestinations);- const overflowPrimaryDestinations = createMemo(() =>- overflowDestinations().filter(- (destination): destination is Extract<MobileNavBarDestination, { kind: 'primary' }> =>- destination.kind === 'primary',- ),- );const overflowUtilityDestinations = createMemo(() =>overflowDestinations().filter((destination): destination is Extract<MobileNavBarDestination, { kind: 'utility' }> =>@@ -41,13 +39,29 @@ export function useMobileNavBarState(props: MobileNavBarProps) {isMobileNavDestinationActive(destination, props.activeTab()),),);+ const platformIsActive = createMemo(() =>+ platformDestinations().some((destination) =>+ isMobileNavDestinationActive(destination, props.activeTab()),+ ),+ );+ const activePlatformDestination = createMemo(() => {+ const destinations = platformDestinations();+ return (+ destinations.find((destination) => destination.tab.id === props.activeTab()) ??+ destinations.find((destination) => destination.tab.id === lastPrimaryTabId()) ??+ destinations[0]+ );+ });- const overflowMenuItems = () =>- Array.from(overflowMenuRef()?.querySelectorAll<HTMLButtonElement>('[role="menuitem"]') ?? []);+ const activeMenuRef = () => (openMenu() === 'platform' ? platformMenuRef() : overflowMenuRef());+ const activeTriggerRef = () =>+ openMenu() === 'platform' ? platformTriggerRef() : overflowTriggerRef();+ const activeMenuItems = () =>+ Array.from(activeMenuRef()?.querySelectorAll<HTMLButtonElement>('[role="menuitem"]') ?? []);- const focusOverflowItem = (target: 'active' | 'first' | 'last') => {+ const focusMenuItem = (target: 'active' | 'first' | 'last') => {queueMicrotask(() => {- const items = overflowMenuItems();+ const items = activeMenuItems();if (items.length === 0) return;const item =target === 'last'@@ -59,25 +73,29 @@ export function useMobileNavBarState(props: MobileNavBarProps) {});};- const openOverflow = (focusTarget: 'active' | 'first' | 'last' = 'active') => {- setIsOverflowOpen(true);- focusOverflowItem(focusTarget);+ const openNavigationMenu = (+ menu: 'platform' | 'overflow',+ focusTarget: 'active' | 'first' | 'last' = 'active',+ ) => {+ setOpenMenu(menu);+ focusMenuItem(focusTarget);};- const closeOverflow = (restoreFocus = false) => {- setIsOverflowOpen(false);+ const closeNavigationMenus = (restoreFocus = false) => {+ const trigger = activeTriggerRef();+ setOpenMenu(null);if (restoreFocus) {- queueMicrotask(() => overflowTriggerRef()?.focus());+ queueMicrotask(() => trigger?.focus());}};createEffect(() => {- if (!isOverflowOpen()) return;+ if (!openMenu()) return;const handlePointerDown = (event: PointerEvent) => {const target = event.target as Node;- if (overflowMenuRef()?.contains(target) || overflowTriggerRef()?.contains(target)) return;- closeOverflow();+ if (activeMenuRef()?.contains(target) || activeTriggerRef()?.contains(target)) return;+ closeNavigationMenus();};document.addEventListener('pointerdown', handlePointerDown);onCleanup(() => document.removeEventListener('pointerdown', handlePointerDown));@@ -86,9 +104,12 @@ export function useMobileNavBarState(props: MobileNavBarProps) {let previousActiveTab = props.activeTab();createEffect(() => {const activeTab = props.activeTab();+ if (platformDestinations().some((destination) => destination.tab.id === activeTab)) {+ setLastPrimaryTabId(activeTab);+ }if (activeTab === previousActiveTab) return;previousActiveTab = activeTab;- closeOverflow();+ closeNavigationMenus();});const handlePrimaryClick = (tab: MobileNavBarPrimaryTab) => {@@ -100,7 +121,7 @@ export function useMobileNavBarState(props: MobileNavBarProps) {};const handleDestinationClick = (destination: MobileNavBarDestination) => {- closeOverflow();+ closeNavigationMenus();if (destination.kind === 'primary') {handlePrimaryClick(destination.tab);return;@@ -108,33 +129,52 @@ export function useMobileNavBarState(props: MobileNavBarProps) {handleUtilityClick(destination.tab);};+ const handlePlatformTriggerClick = () => {+ if (platformDestinations().length === 1) {+ const destination = platformDestinations()[0];+ if (destination) handleDestinationClick(destination);+ return;+ }+ if (openMenu() === 'platform') {+ closeNavigationMenus();+ return;+ }+ openNavigationMenu('platform');+ };++ const handlePlatformTriggerKeyDown = (event: KeyboardEvent) => {+ if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return;+ event.preventDefault();+ openNavigationMenu('platform', event.key === 'ArrowUp' ? 'last' : 'first');+ };+const handleOverflowTriggerClick = () => {- if (isOverflowOpen()) {- closeOverflow();+ if (openMenu() === 'overflow') {+ closeNavigationMenus();return;}- openOverflow();+ openNavigationMenu('overflow');};const handleOverflowTriggerKeyDown = (event: KeyboardEvent) => {if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp') return;event.preventDefault();- openOverflow(event.key === 'ArrowUp' ? 'last' : 'first');+ openNavigationMenu('overflow', event.key === 'ArrowUp' ? 'last' : 'first');};- const handleOverflowMenuKeyDown = (event: KeyboardEvent) => {+ const handleNavigationMenuKeyDown = (event: KeyboardEvent) => {if (event.key === 'Escape') {event.preventDefault();- closeOverflow(true);+ closeNavigationMenus(true);return;}if (event.key === 'Tab') {- closeOverflow();+ closeNavigationMenus();return;}if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(event.key)) return;- const items = overflowMenuItems();+ const items = activeMenuItems();if (items.length === 0) return;event.preventDefault();const currentIndex = items.indexOf(document.activeElement as HTMLButtonElement);@@ -150,17 +190,25 @@ export function useMobileNavBarState(props: MobileNavBarProps) {};return {- closeOverflow,+ activePlatformDestination,+ closeOverflow: closeNavigationMenus,fixedDestinations,handleDestinationClick,- handleOverflowMenuKeyDown,+ handleOverflowMenuKeyDown: handleNavigationMenuKeyDown,handleOverflowTriggerClick,handleOverflowTriggerKeyDown,- isOverflowOpen,+ handlePlatformMenuKeyDown: handleNavigationMenuKeyDown,+ handlePlatformTriggerClick,+ handlePlatformTriggerKeyDown,+ isOverflowOpen: () => openMenu() === 'overflow',+ isPlatformMenuOpen: () => openMenu() === 'platform',overflowDestinations,overflowIsActive,- overflowPrimaryDestinations,overflowUtilityDestinations,+ platformDestinations,+ platformIsActive,+ setPlatformMenuRef,+ setPlatformTriggerRef,setOverflowMenuRef,setOverflowTriggerRef,};