From 49ed687c3bace54fbe40891b4f79c78172345990 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Wed, 7 Oct 2026 13:35:26 -0700 Subject: [PATCH] fix(topbar): mobile overflow menu reaches Version history and the command palette MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On mobile the collapsed topbar had no route to Version history, Export ZIP, Business profile or the command palette. Add a 'Version history' item (only when the site.history command is registered, run through the registry) and a 'More commands…' item that opens the command palette. Co-Authored-By: Claude Opus 5.5 --- craft/src/panels/topbar/TopBar.test.tsx | 60 +++++++++++++++++++ craft/src/panels/topbar/TopBar.tsx | 11 +++- .../src/panels/topbar/TopBarOverflowMenu.tsx | 15 +++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/craft/src/panels/topbar/TopBar.test.tsx b/craft/src/panels/topbar/TopBar.test.tsx index e35174f..ba66996 100644 --- a/craft/src/panels/topbar/TopBar.test.tsx +++ b/craft/src/panels/topbar/TopBar.test.tsx @@ -88,7 +88,12 @@ vi.mock('../sitesmith/SitesmithButton', () => ({ SitesmithButton: () => null })) const openPaletteMock = vi.fn(); vi.mock('../command-palette/CommandPalette', () => ({ openCommandPalette: () => openPaletteMock() })); +const mobileFixture = { isMobile: false }; +vi.mock('../../hooks/useIsMobile', () => ({ useIsMobile: () => mobileFixture.isMobile })); + import { TopBar } from './TopBar'; +import { MobileChromeProvider } from '../../state/MobileChromeContext'; +import { registerCommand } from '../../editor/commands'; import { EditorConfigProvider } from '../../state/EditorConfigContext'; import { WhpConfig } from '../../types'; @@ -149,6 +154,7 @@ afterEach(() => { checkFixture.footerState = null; checkFixture.editingGlobal = false; openPaletteMock.mockReset(); + mobileFixture.isMobile = false; }); describe('TopBar publish-warnings wiring', () => { @@ -430,3 +436,57 @@ describe('TopBar Preview head parity (item 14)', () => { } }); }); + +describe('TopBar mobile overflow menu reaches history and the command palette', () => { + function renderMobile() { + mobileFixture.isMobile = true; + container = document.createElement('div'); + document.body.appendChild(container); + act(() => { + root = createRoot(container); + root.render( + + + {}} /> + + , + ); + }); + act(() => { + container.querySelector('button[aria-label="More options"]')! + .dispatchEvent(new MouseEvent('click', { bubbles: true })); + }); + } + const item = (label: string) => + Array.from(container.querySelectorAll('.topbar-overflow-item')) + .find((b) => (b.textContent || '').includes(label)) || null; + + test('"More commands…" opens the command palette', () => { + renderMobile(); + const btn = item('More commands'); + expect(btn).not.toBeNull(); + act(() => { btn!.dispatchEvent(new MouseEvent('click', { bubbles: true })); }); + expect(openPaletteMock).toHaveBeenCalledTimes(1); + }); + + test('"Version history" appears only when site.history is registered, and runs it', async () => { + renderMobile(); + expect(item('Version history')).toBeNull(); + act(() => { root.unmount(); }); + container.remove(); + const run = vi.fn(); + const off = registerCommand({ id: 'site.history', title: 'Version history…', group: 'site', run }); + try { + renderMobile(); + const btn = item('Version history'); + expect(btn).not.toBeNull(); + await act(async () => { + btn!.dispatchEvent(new MouseEvent('click', { bubbles: true })); + await Promise.resolve(); + }); + expect(run).toHaveBeenCalledTimes(1); + } finally { + off(); + } + }); +}); diff --git a/craft/src/panels/topbar/TopBar.tsx b/craft/src/panels/topbar/TopBar.tsx index 9a3d5e0..a7a2d19 100644 --- a/craft/src/panels/topbar/TopBar.tsx +++ b/craft/src/panels/topbar/TopBar.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState, useEffect, useRef } from 'react'; +import React, { useCallback, useState, useEffect, useRef, useSyncExternalStore } from 'react'; import { useEditor } from '@craftjs/core'; import { useEditorConfig } from '../../state/EditorConfigContext'; import { useWhpApi, SaveOptions } from '../../hooks/useWhpApi'; @@ -22,7 +22,7 @@ import { SaveStatusPill, SaveStatus } from './SaveStatusPill'; import { useSaveGuard } from '../../state/SaveGuardContext'; import { SitesmithButton } from '../sitesmith/SitesmithButton'; import { useSitesmithModal } from '../../state/SitesmithContext'; -import { useRegisterCommands } from '../../editor/commands'; +import { getCommand, subscribeCommands, useRegisterCommands, useRunCommand } from '../../editor/commands'; import { TopBarCommandMenu } from './TopBarCommandMenu'; import { openCommandPalette } from '../command-palette/CommandPalette'; @@ -69,6 +69,11 @@ export const TopBar: React.FC = ({ showGuides, onToggleGuides }) => const [reportOpen, setReportOpen] = useState(false); const isMobile = useIsMobile(); const { open: openSitesmith } = useSitesmithModal(); + // Mobile overflow: Version history only when its command is registered. + // A boolean snapshot (not useCommandState) so TopBar's own per-render + // command re-registration doesn't re-render it in a loop. + const hasHistory = useSyncExternalStore(subscribeCommands, () => !!getCommand('site.history')); + const runCommand = useRunCommand(); const savingRef = useRef(false); const publishingRef = useRef(false); // Read at tick time by autosaveDue, never a stale closure. @@ -447,6 +452,8 @@ export const TopBar: React.FC = ({ showGuides, onToggleGuides }) => onOpenHeadCode={() => setHeadCodeModalOpen(true)} onOpenReportIssue={() => setReportOpen(true)} onPreview={handlePreview} + onOpenCommandPalette={() => openCommandPalette()} + onOpenHistory={hasHistory ? () => { void runCommand('site.history'); } : undefined} sitesmithNode={ openSitesmith()} disabled={!canSave} />} editingDisabled={!canSave} templatesDisabled={isEditingGlobal} diff --git a/craft/src/panels/topbar/TopBarOverflowMenu.tsx b/craft/src/panels/topbar/TopBarOverflowMenu.tsx index 9659f7a..ca580c2 100644 --- a/craft/src/panels/topbar/TopBarOverflowMenu.tsx +++ b/craft/src/panels/topbar/TopBarOverflowMenu.tsx @@ -11,6 +11,11 @@ export interface TopBarOverflowMenuProps { onOpenHeadCode: () => void; onOpenReportIssue: () => void; onPreview: () => void; + /** Opens the command palette -- the mobile route to every registered + * command (Export ZIP, Business profile, ...) that has no item here. */ + onOpenCommandPalette: () => void; + /** Present only when the `site.history` command is registered. */ + onOpenHistory?: () => void; /** Rendered `` -- passed in rather than * re-implemented here so the mobile menu reuses the exact same * lock/cap-aware button the desktop topbar shows. */ @@ -37,6 +42,8 @@ export const TopBarOverflowMenu: React.FC = ({ onOpenHeadCode, onOpenReportIssue, onPreview, + onOpenCommandPalette, + onOpenHistory, sitesmithNode, editingDisabled, templatesDisabled, @@ -97,6 +104,14 @@ export const TopBarOverflowMenu: React.FC = ({