Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

fix: desktop titlebar navigation width animation (#20149)

Innei773312e7f29c
diff --git a/src/features/Electron/titlebar/NavigationBar.test.tsx b/src/features/Electron/titlebar/NavigationBar.test.tsx
index c3fe350813a..495857a1947 100644
--- a/src/features/Electron/titlebar/NavigationBar.test.tsx
+++ b/src/features/Electron/titlebar/NavigationBar.test.tsx
@@ -5,6 +5,8 @@ import NavigationBar from './NavigationBar';
const mocks = vi.hoisted(() => ({
handlers: new Map<string, () => void>(),
+ leftPanelVisible: false,
+ leftPanelWidth: 0,
navigate: vi.fn(),
openAllAgentsDrawer: vi.fn(),
}));
@@ -15,7 +17,7 @@ vi.mock('@lobechat/electron-client-ipc', () => ({
vi.mock('antd-style', async (importOriginal) => ({
...(await importOriginal<object>()),
- createStaticStyles: () => ({ clock: 'clock' }),
+ createStaticStyles: () => ({ clock: 'clock', root: 'root' }),
}));
vi.mock('@/features/NavPanel/ToggleLeftPanelButton', () => ({ default: () => null }));
@@ -23,8 +25,15 @@ vi.mock('@/features/Workspace/useWorkspaceAwareNavigate', () => ({
useWorkspaceAwareNavigate: () => mocks.navigate,
}));
vi.mock('@/services/electron/system', () => ({ electronSystemService: {} }));
-vi.mock('@/store/global', () => ({ useGlobalStore: () => 0 }));
-vi.mock('@/store/global/selectors', () => ({ systemStatusSelectors: {} }));
+vi.mock('@/store/global', () => ({
+ useGlobalStore: (selector: (state: unknown) => unknown) => selector({}),
+}));
+vi.mock('@/store/global/selectors', () => ({
+ systemStatusSelectors: {
+ leftPanelWidth: () => mocks.leftPanelWidth,
+ showLeftPanel: () => mocks.leftPanelVisible,
+ },
+}));
vi.mock('@/store/home', () => ({
getHomeStoreState: () => ({ openAllAgentsDrawer: mocks.openAllAgentsDrawer }),
}));
@@ -48,6 +57,8 @@ vi.mock('./TrayMenu/useTrayMenuSync', () => ({ useTrayMenuSync: vi.fn() }));
describe('NavigationBar tray broadcasts', () => {
beforeEach(() => {
mocks.handlers.clear();
+ mocks.leftPanelVisible = false;
+ mocks.leftPanelWidth = 0;
vi.clearAllMocks();
});
@@ -67,4 +78,18 @@ describe('NavigationBar tray broadcasts', () => {
expect(mocks.navigate).toHaveBeenCalledWith('/acme', { escape: true });
expect(mocks.openAllAgentsDrawer).toHaveBeenCalled();
});
+
+ it('keeps titlebar navigation width animatable when the sidebar is collapsed', () => {
+ const { container, unmount } = render(<NavigationBar />);
+ const navigationBar = container.querySelector('.root') as HTMLElement;
+
+ expect(navigationBar).toHaveStyle({ width: '150px' });
+ unmount();
+
+ mocks.leftPanelVisible = true;
+ mocks.leftPanelWidth = 280;
+ const expanded = render(<NavigationBar />);
+
+ expect(expanded.container.querySelector('.root')).toHaveStyle({ width: '268px' });
+ });
});
diff --git a/src/features/Electron/titlebar/NavigationBar.tsx b/src/features/Electron/titlebar/NavigationBar.tsx
index 859ba028128..aa9cce26042 100644
--- a/src/features/Electron/titlebar/NavigationBar.tsx
+++ b/src/features/Electron/titlebar/NavigationBar.tsx
@@ -25,6 +25,8 @@ import RecentlyViewed from './RecentlyViewed';
import { useTrayMenuSync } from './TrayMenu/useTrayMenuSync';
const isMac = isMacOS();
+const COLLAPSED_NAVIGATION_BAR_WIDTH = 150;
+const MAC_COLLAPSED_NAVIGATION_BAR_WIDTH = 116;
// A persistent titlebar toggle must not share the sidebar toggle's id, or it
// would create a duplicate DOM id and get caught by NavPanelDraggable's hover CSS.
@@ -47,6 +49,13 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
background-color: ${cssVar.colorFillTertiary};
}
`,
+ root: css`
+ transition: width 0.2s ${cssVar.motionEaseOut};
+
+ @media (prefers-reduced-motion: reduce) {
+ transition: none;
+ }
+ `,
}));
const NavigationBar = memo(() => {
@@ -119,11 +128,18 @@ const NavigationBar = memo(() => {
const isLeftPanelVisible = leftPanelWidth > 0;
const macTrafficLightPadding = getMacTrafficLightPadding(isMac, isWindowFullScreen);
+ const collapsedWidth = isMac
+ ? MAC_COLLAPSED_NAVIGATION_BAR_WIDTH
+ : COLLAPSED_NAVIGATION_BAR_WIDTH;
+ const navigationWidth = isLeftPanelVisible
+ ? Math.max(leftPanelWidth - 12, collapsedWidth)
+ : collapsedWidth;
return (
<Flexbox
horizontal
align="center"
+ className={styles.root}
data-width={leftPanelWidth}
gap={8}
justify={isMac ? 'space-between' : 'end'}
@@ -131,9 +147,8 @@ const NavigationBar = memo(() => {
paddingLeft: macTrafficLightPadding,
paddingRight: 8,
// Expanded: span the sidebar width so the right group hugs its right edge.
- // Collapsed (macOS): shrink to content so the controls cluster at the left edge.
- width: isLeftPanelVisible ? `${leftPanelWidth - 12}px` : isMac ? 'auto' : '150px',
- transition: !isLeftPanelVisible ? 'width 0.2s' : 'none',
+ // Collapsed: keep a concrete width so the titlebar controls can animate.
+ width: navigationWidth,
}}
>
{/* The persistent panel toggle is macOS-only; other platforms keep the