Skip to content

Commit efe52c6

Browse files
hunterbohmclaude
andcommitted
fix(web): thread shortcuts work in narrow windows with the sidebar closed
The narrow-window sidebar is a sheet that unmounted its content when closed. The thread list owns the Mod+1-9 and Mod+Shift+[/] handlers, so those shortcuts did nothing until the sheet was opened. Keep the sheet content mounted and track the sheet's finished transitions to hide the floating sidebar toggle while the sheet is on screen. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e79119b commit efe52c6

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

‎apps/web/src/components/AppSidebarLayout.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ function readInitialThreadSidebarWidth(): number {
121121
function SidebarControl() {
122122
const usagePageOpen = useLocation({ select: (location) => location.pathname === "/usage" });
123123
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
124-
const { toggleSidebar, isMobile, mobileSheetMounted } = useSidebar();
124+
const { toggleSidebar, isMobile, mobileSheetShown } = useSidebar();
125125
const isSidebarVisible = useSidebarVisibility();
126126
const environmentIdentificationMode = useEnvironmentIdentificationMode();
127127
const stageBackdropVariant = useSidebarStageBackdropVariant(
@@ -174,7 +174,7 @@ function SidebarControl() {
174174
<div
175175
className={cn(
176176
"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",
177-
isMobile && mobileSheetMounted && "hidden",
177+
isMobile && mobileSheetShown && "hidden",
178178
)}
179179
data-sidebar-control=""
180180
>

‎apps/web/src/components/ui/sidebar.tsx‎

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ type SidebarContextProps = {
3535
open: boolean;
3636
setOpen: (open: boolean) => void;
3737
openMobile: boolean;
38-
mobileSheetMounted: boolean;
39-
setMobileSheetElement: (element: HTMLDivElement | null) => void;
38+
mobileSheetShown: boolean;
39+
setMobileSheetOpened: (opened: boolean) => void;
4040
setOpenMobile: (open: boolean) => void;
4141
isMobile: boolean;
4242
toggleSidebar: () => void;
@@ -109,10 +109,11 @@ function SidebarProvider({
109109
}) {
110110
const isMobile = useIsMobile();
111111
const [openMobile, setOpenMobile] = React.useState(false);
112-
const [mobileSheetMounted, setMobileSheetMounted] = React.useState(false);
113-
const setMobileSheetElement = (element: HTMLDivElement | null) => {
114-
setMobileSheetMounted(element !== null);
115-
};
112+
// The last finished sheet transition, so a closing sheet still counts as shown.
113+
const [mobileSheetOpened, setMobileSheetOpened] = React.useState(false);
114+
// Widening the window mid-close unmounts the sheet before its transition reports.
115+
if (!isMobile && mobileSheetOpened) setMobileSheetOpened(false);
116+
const mobileSheetShown = openMobile || mobileSheetOpened;
116117

117118
const [_open, _setOpen] = React.useState(defaultOpen);
118119
const open = openProp ?? _open;
@@ -142,8 +143,8 @@ function SidebarProvider({
142143
isMobile,
143144
open,
144145
openMobile,
145-
mobileSheetMounted,
146-
setMobileSheetElement,
146+
mobileSheetShown,
147+
setMobileSheetOpened,
147148
setOpen,
148149
setOpenMobile,
149150
state,
@@ -214,7 +215,7 @@ function Sidebar({
214215
collapsible?: "offcanvas" | "icon" | "none";
215216
resizable?: boolean | SidebarResizableOptions;
216217
}) {
217-
const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar();
218+
const { isMobile, state, openMobile, setOpenMobile, setMobileSheetOpened } = useSidebar();
218219
// The rail's width restore and drag refresh key on this value.
219220
const resolvedResizable = resolveSidebarResizable({ collapsible, isMobile, resizable });
220221
const instanceContextValue: SidebarInstanceContextProps = { side, resizable: resolvedResizable };
@@ -239,9 +240,14 @@ function Sidebar({
239240
if (isMobile) {
240241
return (
241242
<SidebarInstanceContext value={instanceContextValue}>
242-
<Sheet onOpenChange={setOpenMobile} open={openMobile}>
243+
<Sheet
244+
onOpenChange={setOpenMobile}
245+
onOpenChangeComplete={setMobileSheetOpened}
246+
open={openMobile}
247+
>
248+
{/* Kept mounted so the content's window shortcuts work while the sheet is closed. */}
243249
<SheetPopup
244-
ref={setMobileSheetElement}
250+
keepMounted
245251
className={cn(
246252
"w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground",
247253
className,

0 commit comments

Comments
 (0)