Skip to content
TypeScript

fix(web): sidebar toggle no longer sits under the macOS window buttons (#18193)

Hasan Shoaibdf78114360b7
diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsx
index 00d5c05ef08..fd56ee8ca5a 100644
--- a/apps/web/src/components/AppSidebarLayout.tsx
+++ b/apps/web/src/components/AppSidebarLayout.tsx
@@ -83,7 +83,7 @@ function readInitialThreadSidebarWidth(): number {
function SidebarControl() {
const usagePageOpen = useLocation({ select: (location) => location.pathname === "/usage" });
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
- const { toggleSidebar } = useSidebar();
+ const { toggleSidebar, isMobile, mobileSheetMounted } = useSidebar();
const isSidebarVisible = useSidebarVisibility();
const environmentIdentificationMode = useEnvironmentIdentificationMode();
const stageBackdropVariant = useSidebarStageBackdropVariant(
@@ -138,8 +138,12 @@ function SidebarControl() {
// The right-side layout controls carry mr-px (border compensation inside
// the panel), so the trigger mirrors it: both clusters sit one extra pixel
// off their edge and the titlebar reads symmetric.
+ // The sheet owns its trigger until its closing transition unmounts it.
<div
- className="pointer-events-none fixed left-[var(--workspace-controls-left)] top-[var(--workspace-controls-top)] z-50 ml-px flex h-[var(--workspace-topbar-height)] items-center"
+ className={cn(
+ "pointer-events-none fixed left-[var(--workspace-controls-left)] top-[var(--workspace-controls-top)] z-50 ml-px flex h-[var(--workspace-topbar-height)] items-center",
+ isMobile && mobileSheetMounted && "hidden",
+ )}
data-sidebar-control=""
>
<Tooltip>
@@ -259,12 +263,15 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
? getWindowFullscreenState()
: false;
});
+ const windowControlsInsetStyle = (
+ isMacosDesktop && !isWindowFullscreen
+ ? { "--workspace-controls-left": MACOS_TRAFFIC_LIGHTS_LEFT_INSET }
+ : {}
+ ) as CSSProperties;
const sidebarProviderStyle = {
"--sidebar-width": `${clampThreadSidebarWidth(sidebarWidth, sidebarMinimumWidth, sidebarMaximumWidth)}px`,
"--panel-animation-duration": `${panelAnimationDurationMs}ms`,
- ...(isMacosDesktop && !isWindowFullscreen
- ? { "--workspace-controls-left": MACOS_TRAFFIC_LIGHTS_LEFT_INSET }
- : {}),
+ ...windowControlsInsetStyle,
} as CSSProperties;
useEffect(() => {
@@ -329,6 +336,8 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
storageKey: THREAD_SIDEBAR_WIDTH_STORAGE_KEY,
onResize: setSidebarWidth,
}}
+ // The narrow-window sidebar is a sheet, portaled outside the provider's styles.
+ style={windowControlsInsetStyle}
>
{isOnSettings ? (
<>
diff --git a/apps/web/src/components/sidebar/SidebarChrome.tsx b/apps/web/src/components/sidebar/SidebarChrome.tsx
index 716f96ceecd..ae05529374c 100644
--- a/apps/web/src/components/sidebar/SidebarChrome.tsx
+++ b/apps/web/src/components/sidebar/SidebarChrome.tsx
@@ -51,16 +51,20 @@ export const SidebarChromeHeader = memo(function SidebarChromeHeader({
// The titlebar row, not a padded SidebarHeader: it aligns to the window controls.
<div
className={cn(
- "relative flex h-[var(--workspace-topbar-height)] shrink-0 flex-row items-center gap-2 px-3 md:pl-0",
+ "relative flex h-[var(--workspace-topbar-height)] shrink-0 flex-row items-center gap-2 pr-3",
isElectron && "drag-region",
)}
>
{backdropVariant ? <SidebarStageBackdrop variant={backdropVariant} /> : null}
- <SidebarTrigger
- // Over the stage artwork: the media viewer's control-on-imagery treatment.
- variant={backdropVariant ? "media-navigation" : "ghost"}
- className="relative top-auto z-10 translate-y-0 md:hidden"
- />
+ {/* Match the fixed control's inset and border compensation inside the sheet's safe area. */}
+ <div className="relative top-[calc(var(--workspace-controls-top)-env(safe-area-inset-top))] z-10 ml-[calc(var(--workspace-controls-left)+1px-env(safe-area-inset-left))] flex shrink-0 items-center md:hidden">
+ <SidebarTrigger
+ // Over the stage artwork: the media viewer's control-on-imagery treatment.
+ variant={backdropVariant ? "media-navigation" : "ghost"}
+ className="relative top-auto translate-y-0"
+ aria-label="Toggle main sidebar"
+ />
+ </div>
{/* One visible line: the pill wraps onto the clipped second line once it no longer fits.
The padding keeps the brand's focus ring inside the clip. */}
<div className="relative z-10 flex h-8 min-w-0 flex-1 flex-wrap content-start items-center gap-x-2 overflow-hidden py-0.5">
diff --git a/apps/web/src/components/ui/sidebar.tsx b/apps/web/src/components/ui/sidebar.tsx
index c1bd6b277c5..a22e3c44bbd 100644
--- a/apps/web/src/components/ui/sidebar.tsx
+++ b/apps/web/src/components/ui/sidebar.tsx
@@ -28,12 +28,15 @@ const SIDEBAR_WIDTH = "16rem";
const SIDEBAR_WIDTH_MOBILE = "calc(100vw - var(--spacing(3)))";
const SIDEBAR_WIDTH_ICON = "3rem";
const SIDEBAR_RESIZE_DEFAULT_MIN_WIDTH = 16 * 16;
+const SIDEBAR_TITLEBAR_CONTROL_SIZE = "max-sm:[--workspace-titlebar-control-size:--spacing(8)]";
type SidebarContextProps = {
state: ResponsiveSidebarState;
open: boolean;
setOpen: (open: boolean) => void;
openMobile: boolean;
+ mobileSheetMounted: boolean;
+ setMobileSheetElement: (element: HTMLDivElement | null) => void;
setOpenMobile: (open: boolean) => void;
isMobile: boolean;
toggleSidebar: () => void;
@@ -106,6 +109,10 @@ function SidebarProvider({
}) {
const isMobile = useIsMobile();
const [openMobile, setOpenMobile] = React.useState(false);
+ const [mobileSheetMounted, setMobileSheetMounted] = React.useState(false);
+ const setMobileSheetElement = React.useCallback((element: HTMLDivElement | null) => {
+ setMobileSheetMounted(element !== null);
+ }, []);
// This is the internal state of the sidebar.
// We use openProp and setOpenProp for control from outside the component.
@@ -145,12 +152,23 @@ function SidebarProvider({
isMobile,
open,
openMobile,
+ mobileSheetMounted,
+ setMobileSheetElement,
setOpen,
setOpenMobile,
state,
toggleSidebar,
}),
- [state, open, setOpen, isMobile, openMobile, toggleSidebar],
+ [
+ state,
+ open,
+ setOpen,
+ isMobile,
+ openMobile,
+ mobileSheetMounted,
+ setMobileSheetElement,
+ toggleSidebar,
+ ],
);
return (
@@ -158,7 +176,8 @@ function SidebarProvider({
<div
// Inset layouts opt into bg-sidebar through className.
className={cn(
- "group/sidebar-wrapper flex min-h-svh w-full max-sm:[--workspace-titlebar-control-size:--spacing(8)]",
+ "group/sidebar-wrapper flex min-h-svh w-full",
+ SIDEBAR_TITLEBAR_CONTROL_SIZE,
className,
)}
data-sidebar-state={state}
@@ -194,7 +213,7 @@ function Sidebar({
collapsible?: "offcanvas" | "icon" | "none";
resizable?: boolean | SidebarResizableOptions;
}) {
- const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
+ const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar();
const resolvedResizable = React.useMemo<SidebarResolvedResizableOptions | null>(() => {
if (isMobile || collapsible === "none" || !resizable) {
return null;
@@ -236,6 +255,7 @@ function Sidebar({
<SidebarInstanceContext value={instanceContextValue}>
<Sheet onOpenChange={setOpenMobile} open={openMobile}>
<SheetPopup
+ ref={setMobileSheetElement}
className={cn(
"w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground",
className,
@@ -258,6 +278,7 @@ function Sidebar({
<div
className={cn(
"flex h-full w-full flex-col pb-safe pt-safe",
+ SIDEBAR_TITLEBAR_CONTROL_SIZE,
side === "left" ? "pl-safe" : "pr-safe",
)}
{...props}