diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsx index 91df5616f7f50..c2b3c67b089e7 100644 --- a/apps/web/src/components/AppSidebarLayout.tsx +++ b/apps/web/src/components/AppSidebarLayout.tsx @@ -31,7 +31,7 @@ import { selectActiveRightPanel, useRightPanelStore } from "../rightPanelStore"; import { selectThreadTerminalUiState, useTerminalUiStateStore } from "../terminalUiStateStore"; import { cn, isMacPlatform } from "../lib/utils"; import { primaryServerKeybindingsAtom } from "../state/server"; -import { useEnvironmentIdentificationMode } from "../hooks/useSettings"; +import { useClientSettings, useEnvironmentIdentificationMode } from "../hooks/useSettings"; import { PanelAnimationSuppressionProvider, usePanelAnimationSettings, @@ -402,6 +402,10 @@ function SidebarControl() { } export function AppSidebarLayout({ children }: { children: ReactNode }) { + const revealOnHover = useClientSettings((settings) => settings.sidebarRevealOnHover); + const hoverAnimationDurationMs = useClientSettings( + (settings) => settings.sidebarHoverAnimationDurationMs ?? settings.panelAnimationDurationMs, + ); const sidebarArea = workspaceAreaProps("sidebar", 0, "Threads"); const [sidebarRouteReveal] = useState(() => ({ observedKey: null, @@ -454,6 +458,8 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { = { bars: "Bars", }; +function PanelDurationSlider({ + durationMs, + id, + label, + onChange, +}: { + durationMs: number; + id: string; + label: string; + onChange: (durationMs: number) => void; +}) { + const ratio = + (durationMs - MIN_PANEL_ANIMATION_DURATION_MS) / + (MAX_PANEL_ANIMATION_DURATION_MS - MIN_PANEL_ANIMATION_DURATION_MS); + return ( +
+ + {durationMs} ms + + { + const value = Number(event.currentTarget.value); + if ( + Number.isInteger(value) && + value >= MIN_PANEL_ANIMATION_DURATION_MS && + value <= MAX_PANEL_ANIMATION_DURATION_MS + ) + onChange(value); + }} + step={25} + style={ + { + "--settings-slider-progress": `${ratio * 100}%`, + "--settings-slider-fill-offset": `${0.5 - ratio}rem`, + } as CSSProperties + } + type="range" + value={durationMs} + /> +
+ ); +} + export function AppearanceSettingsPanel() { const { appearanceMode, @@ -134,13 +185,6 @@ export function AppearanceSettingsPanel() { "--settings-slider-progress": `${appearanceContrastRatio * 100}%`, "--settings-slider-fill-offset": `${0.5 - appearanceContrastRatio}rem`, } as CSSProperties; - const panelAnimationDurationRatio = - (settings.panelAnimationDurationMs - MIN_PANEL_ANIMATION_DURATION_MS) / - (MAX_PANEL_ANIMATION_DURATION_MS - MIN_PANEL_ANIMATION_DURATION_MS); - const panelAnimationDurationSliderStyle = { - "--settings-slider-progress": `${panelAnimationDurationRatio * 100}%`, - "--settings-slider-fill-offset": `${0.5 - panelAnimationDurationRatio}rem`, - } as CSSProperties; return ( @@ -348,6 +392,86 @@ export function AppearanceSettingsPanel() { /> } /> + + updateSettings({ + sidebarRevealOnHover: DEFAULT_UNIFIED_SETTINGS.sidebarRevealOnHover, + }) + } + /> + ) : null + } + control={ + updateSettings({ sidebarRevealOnHover: checked })} + aria-label="Reveal sidebar on hover" + /> + } + /> + + updateSettings({ + sidebarHoverAnimationDurationMs: + DEFAULT_UNIFIED_SETTINGS.sidebarHoverAnimationDurationMs, + }) + } + /> + ) : null + } + control={ +
+ + {settings.sidebarHoverAnimationDurationMs !== null && ( + + updateSettings({ sidebarHoverAnimationDurationMs }) + } + /> + )} +
+ } + /> -
- - {settings.panelAnimationDurationMs} ms - - { - const panelAnimationDurationMs = Number(event.currentTarget.value); - if ( - Number.isInteger(panelAnimationDurationMs) && - panelAnimationDurationMs >= MIN_PANEL_ANIMATION_DURATION_MS && - panelAnimationDurationMs <= MAX_PANEL_ANIMATION_DURATION_MS - ) { - updateSettings({ panelAnimationDurationMs }); - } - }} - step={25} - style={panelAnimationDurationSliderStyle} - type="range" - value={settings.panelAnimationDurationMs} - /> -
+ + updateSettings({ panelAnimationDurationMs }) + } + /> } resetAction={ diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index 362210f96eee1..57d4da11c984f 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -483,6 +483,13 @@ export function useSettingsRestore(onRestored?: () => void) { ...(settings.sidebarWorkingShelfEnabled !== DEFAULT_UNIFIED_SETTINGS.sidebarWorkingShelfEnabled ? ["Working section"] : []), + ...(settings.sidebarRevealOnHover !== DEFAULT_UNIFIED_SETTINGS.sidebarRevealOnHover + ? ["Reveal sidebar on hover"] + : []), + ...(settings.sidebarHoverAnimationDurationMs !== + DEFAULT_UNIFIED_SETTINGS.sidebarHoverAnimationDurationMs + ? ["Hover animation speed"] + : []), ...(settings.sidebarAutoSettleAfterDays !== DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays ? ["Auto-settle inactive threads"] : []), @@ -649,6 +656,8 @@ export function useSettingsRestore(onRestored?: () => void) { sidebarProjectGroupingMode: DEFAULT_UNIFIED_SETTINGS.sidebarProjectGroupingMode, sidebarProjectSortOrder: DEFAULT_UNIFIED_SETTINGS.sidebarProjectSortOrder, sidebarWorkingShelfEnabled: DEFAULT_UNIFIED_SETTINGS.sidebarWorkingShelfEnabled, + sidebarRevealOnHover: DEFAULT_UNIFIED_SETTINGS.sidebarRevealOnHover, + sidebarHoverAnimationDurationMs: DEFAULT_UNIFIED_SETTINGS.sidebarHoverAnimationDurationMs, sidebarAutoSettleAfterDays: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays, sidebarAutoSettleKeepPullRequests: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleKeepPullRequests, sidebarAutoSettleOnMerge: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge, diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.ts index e61a064431c55..2f944b7944e6c 100644 --- a/apps/web/src/components/settings/settingsSearch.ts +++ b/apps/web/src/components/settings/settingsSearch.ts @@ -360,6 +360,18 @@ export const SETTINGS_SEARCH_ITEMS = [ title: "Panel animations", to: "/settings/appearance", }, + { + id: "sidebar-reveal-on-hover", + title: "Reveal sidebar on hover", + to: "/settings/appearance", + searchTerms: ["sidebar auto appear hover peek hidden left edge mouse"], + }, + { + id: "sidebar-hover-animation-speed", + title: "Hover animation speed", + to: "/settings/appearance", + searchTerms: ["sidebar transition duration separate override slide in out animation"], + }, { id: "environment-identification", title: "Environment identification", diff --git a/apps/web/src/components/ui/sidebar.browser.test.tsx b/apps/web/src/components/ui/sidebar.browser.test.tsx index 288367fa4a3ed..9ed5e45affc77 100644 --- a/apps/web/src/components/ui/sidebar.browser.test.tsx +++ b/apps/web/src/components/ui/sidebar.browser.test.tsx @@ -1,8 +1,12 @@ import { page, userEvent } from "vite-plus/test/browser"; import { describe, expect, it, vi } from "vite-plus/test"; +import type { CSSProperties } from "react"; -import { render } from "../../../test/render"; +import { act, fakeTimers, render } from "../../../test/render"; import { Sidebar, SidebarProvider, SidebarRail, SidebarTrigger, useSidebar } from "./sidebar"; +import { Menu, MenuTrigger, MenuPopup, MenuItem } from "./menu"; +import { ensureLocalApi } from "~/localApi"; +import "~/index.css"; function CollapseFromInside() { const { setOpen } = useSidebar(); @@ -13,11 +17,27 @@ function CollapseFromInside() { ); } -function Harness(props: { readonly onResize?: (width: number) => void }) { +function Harness(props: { + readonly onResize?: (width: number) => void; + readonly revealOnHover?: boolean; + readonly defaultOpen?: boolean; + readonly panelAnimationDurationMs?: number; + readonly hoverAnimationDurationMs?: number; +}) { return ( - + void }) { }} > + + Sidebar menu + + Menu action + + + + ); } describe("Sidebar", () => { + it.each([ + { panel: 0, hover: 200, reduced: false, expected: 200 }, + { panel: 300, hover: 75, reduced: false, expected: 75 }, + { panel: 300, hover: 0, reduced: false, expected: 0 }, + { panel: 0, hover: 200, reduced: true, expected: 0 }, + ])( + "keeps hover enter/exit at $expected ms with panel=$panel, hover=$hover, reduced=$reduced", + async ({ panel, hover, reduced, expected }) => { + await page.viewport(1280, 800); + const matchMedia = window.matchMedia.bind(window); + using _media = vi.spyOn(window, "matchMedia").mockImplementation((query) => { + const result = matchMedia(query); + return query === "(prefers-reduced-motion: reduce)" + ? Object.defineProperty(result, "matches", { value: reduced }) + : result; + }); + await using screen = await render( + , + { + router: false /* no routes involved */, + }, + ); + using _timers = fakeTimers(); + const sidebar = screen.container.querySelector('[data-slot="sidebar"]')!; + const container = sidebar.querySelector('[data-slot="sidebar-container"]')!; + const gap = sidebar.querySelector('[data-slot="sidebar-gap"]')!; + const edge = screen.container.querySelector('[data-slot="sidebar-hover-edge"]')!; + expect(getComputedStyle(container).transitionDuration).toBe(`${panel / 1000}s`); + edge.dispatchEvent(new PointerEvent("pointerover", { bubbles: true, pointerType: "mouse" })); + await act(() => vi.advanceTimersByTimeAsync(110)); + expect(sidebar.inert).toBe(false); + expect(getComputedStyle(container).transitionDuration).toBe(`${expected / 1000}s`); + expect(gap.getBoundingClientRect().width).toBe(0); + edge.dispatchEvent( + new PointerEvent("pointerout", { + bubbles: true, + pointerType: "mouse", + relatedTarget: document.body, + }), + ); + await act(() => vi.advanceTimersByTimeAsync(200)); + expect(sidebar.inert).toBe(true); + expect(getComputedStyle(container).transitionDuration).toBe(`${expected / 1000}s`); + const trigger = screen.container.querySelector( + '[data-sidebar="trigger"]', + )!; + await act(() => trigger.click()); + expect(sidebar.dataset.state).toBe("expanded"); + expect(getComputedStyle(container).transitionDuration).toBe(`${panel / 1000}s`); + await act(() => trigger.click()); + expect(sidebar.dataset.state).toBe("collapsed"); + expect(getComputedStyle(container).transitionDuration).toBe(`${panel / 1000}s`); + }, + ); + + it("peeks only for mouse hover, overlays the chat, and keeps the explicit toggle available", async () => { + await page.viewport(1280, 800); + await using screen = await render(, { + router: false /* no routes involved */, + }); + using _timers = fakeTimers(); + const edge = screen.container.querySelector('[data-slot="sidebar-hover-edge"]')!; + const sidebar = screen.container.querySelector('[data-slot="sidebar"]')!; + const enter = async (pointerType: string) => { + edge.dispatchEvent(new PointerEvent("pointerover", { bubbles: true, pointerType })); + await act(() => vi.advanceTimersByTimeAsync(110)); + }; + for (const pointerType of ["touch", "pen"]) { + await enter(pointerType); + expect(sidebar.inert).toBe(true); + } + await enter("mouse"); + expect(sidebar.inert).toBe(false); + expect(sidebar.dataset.state).toBe("collapsed"); + expect(sidebar.contains(document.elementFromPoint(20, 325))).toBe(true); + expect(sidebar.querySelector('[data-slot="sidebar-gap"]')!.getBoundingClientRect().width).toBe( + 0, + ); + expect( + sidebar.querySelector('[data-slot="sidebar-container"]')!.getBoundingClientRect().left, + ).toBe(0); + const rail = sidebar.querySelector('[data-sidebar="rail"]')!; + const railBounds = rail.getBoundingClientRect(); + expect( + rail.contains(document.elementFromPoint(railBounds.left + railBounds.width / 2, 300)), + ).toBe(true); + const pointer = { + bubbles: true, + cancelable: true, + pointerId: 1, + button: 0, + pointerType: "mouse", + }; + rail.dispatchEvent(new PointerEvent("pointerdown", { ...pointer, clientX: 255 })); + rail.dispatchEvent(new PointerEvent("pointerup", { ...pointer, clientX: 350 })); + await act(() => vi.advanceTimersByTimeAsync(0)); + expect(sidebar.dataset.state).toBe("collapsed"); + expect(sidebar.querySelector('[data-slot="sidebar-gap"]')!.getBoundingClientRect().width).toBe( + 0, + ); + expect( + sidebar.querySelector('[data-slot="sidebar-container"]')!.getBoundingClientRect().width, + ).toBe(351); + screen.container.querySelector('[data-slot="sidebar-trigger"]')!.click(); + await act(() => vi.advanceTimersByTimeAsync(0)); + expect(sidebar.dataset.state).toBe("expanded"); + expect(sidebar.inert).toBe(false); + }); + + it("retains the peek for its popup and context menus, then dismisses on departure", async () => { + await page.viewport(1280, 800); + await using screen = await render(, { + router: false /* no routes involved */, + }); + const edge = screen.container.querySelector('[data-slot="sidebar-hover-edge"]')!; + const sidebar = screen.container.querySelector('[data-slot="sidebar"]')!; + await userEvent.hover(edge, { + position: { x: 2, y: window.innerHeight / 2 - edge.getBoundingClientRect().top }, + }); + await vi.waitFor(() => expect(sidebar.inert).toBe(false)); + await userEvent.click(screen.getByRole("button", { name: "Sidebar menu" })); + await userEvent.hover(page.getByRole("menuitem", { name: "Menu action" })); + expect(sidebar.inert).toBe(false); + await userEvent.keyboard("{Escape}"); + const menu = ensureLocalApi().contextMenu.show([{ id: "action", label: "Context action" }], { + x: 100, + y: 100, + }); + await expect.element(page.getByRole("menuitem", { name: "Context action" })).toBeVisible(); + await userEvent.hover(screen.getByRole("button", { name: "Outside" })); + expect(sidebar.inert).toBe(false); + await ensureLocalApi().contextMenu.close(); + await menu; + await vi.waitFor(() => expect(sidebar.inert).toBe(true)); + }); + it("hands focus to the outside trigger when it collapses around the focused control", async () => { await page.viewport(1280, 800); await using screen = await render(, { router: false /* no routes involved */ }); diff --git a/apps/web/src/components/ui/sidebar.tsx b/apps/web/src/components/ui/sidebar.tsx index e99509c8ce60e..b47c7d79a29fc 100644 --- a/apps/web/src/components/ui/sidebar.tsx +++ b/apps/web/src/components/ui/sidebar.tsx @@ -22,6 +22,7 @@ import { setLocalStorageItem } from "~/hooks/useLocalStorage"; import { resolveSidebarState, type ResponsiveSidebarState } from "./sidebarState"; import * as Schema from "effect/Schema"; import { announceSidebarVisibility } from "~/lib/accessibilityAnnouncements"; +import { useSidebarPeek } from "./sidebarPeek"; const SIDEBAR_COOKIE_NAME = "sidebar_state"; const SIDEBAR_COOKIE_MAX_AGE = 60 * 60 * 24 * 7; @@ -78,6 +79,7 @@ type SidebarResolvedResizableOptions = { type SidebarInstanceContextProps = { resizable: SidebarResolvedResizableOptions | null; side: "left" | "right"; + revealed?: boolean; }; const SidebarContext = React.createContext(null); @@ -264,21 +266,40 @@ function Sidebar({ side = "left", variant = "sidebar", collapsible = "offcanvas", + revealOnHover = false, + hoverAnimationDurationMs = 0, resizable = false, className, + style, children, ...props }: React.ComponentProps<"div"> & { side?: "left" | "right"; variant?: "sidebar" | "floating" | "inset"; collapsible?: "offcanvas" | "icon" | "none"; + revealOnHover?: boolean; + hoverAnimationDurationMs?: number; resizable?: boolean | SidebarResizableOptions; }) { const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar(); const offcanvasCollapsed = !isMobile && collapsible === "offcanvas" && state === "collapsed"; + const hasHover = useMediaQuery("(any-hover: hover) and (any-pointer: fine)"); + const { ref: peekRef, ...peek } = useSidebarPeek( + revealOnHover && offcanvasCollapsed && side === "left" && hasHover, + ); + const prefersReducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)"); + const hoverTransition = offcanvasCollapsed && peek.hasRevealed; + const hoverDurationMs = prefersReducedMotion ? 0 : hoverAnimationDurationMs; + const containerStyle = hoverTransition + ? ({ ...style, "--panel-animation-duration": `${hoverDurationMs}ms` } as React.CSSProperties) + : style; const resolvedResizable = resolveSidebarResizable({ collapsible, isMobile, resizable }); - const instanceContextValue: SidebarInstanceContextProps = { side, resizable: resolvedResizable }; + const instanceContextValue: SidebarInstanceContextProps = { + side, + resizable: resolvedResizable, + revealed: peek.revealed, + }; if (collapsible === "none") { return ( @@ -289,6 +310,7 @@ function Sidebar({ className, )} data-slot="sidebar" + style={style} {...props} > {children} @@ -328,6 +350,7 @@ function Sidebar({ SIDEBAR_TITLEBAR_CONTROL_SIZE, side === "left" ? "pl-safe" : "pr-safe", )} + style={style} {...props} > {children} @@ -340,11 +363,28 @@ function Sidebar({ return ( + {revealOnHover && offcanvasCollapsed && side === "left" && hasHover && ( +