@@ -28,12 +28,15 @@ const SIDEBAR_WIDTH = "16rem";
2828const SIDEBAR_WIDTH_MOBILE = "calc(100vw - var(--spacing(3)))" ;
2929const SIDEBAR_WIDTH_ICON = "3rem" ;
3030const SIDEBAR_RESIZE_DEFAULT_MIN_WIDTH = 16 * 16 ;
31+ const SIDEBAR_TITLEBAR_CONTROL_SIZE = "max-sm:[--workspace-titlebar-control-size:--spacing(8)]" ;
3132
3233type SidebarContextProps = {
3334 state : ResponsiveSidebarState ;
3435 open : boolean ;
3536 setOpen : ( open : boolean ) => void ;
3637 openMobile : boolean ;
38+ mobileSheetMounted : boolean ;
39+ setMobileSheetElement : ( element : HTMLDivElement | null ) => void ;
3740 setOpenMobile : ( open : boolean ) => void ;
3841 isMobile : boolean ;
3942 toggleSidebar : ( ) => void ;
@@ -106,6 +109,10 @@ function SidebarProvider({
106109} ) {
107110 const isMobile = useIsMobile ( ) ;
108111 const [ openMobile , setOpenMobile ] = React . useState ( false ) ;
112+ const [ mobileSheetMounted , setMobileSheetMounted ] = React . useState ( false ) ;
113+ const setMobileSheetElement = React . useCallback ( ( element : HTMLDivElement | null ) => {
114+ setMobileSheetMounted ( element !== null ) ;
115+ } , [ ] ) ;
109116
110117 // This is the internal state of the sidebar.
111118 // We use openProp and setOpenProp for control from outside the component.
@@ -145,20 +152,32 @@ function SidebarProvider({
145152 isMobile,
146153 open,
147154 openMobile,
155+ mobileSheetMounted,
156+ setMobileSheetElement,
148157 setOpen,
149158 setOpenMobile,
150159 state,
151160 toggleSidebar,
152161 } ) ,
153- [ state , open , setOpen , isMobile , openMobile , toggleSidebar ] ,
162+ [
163+ state ,
164+ open ,
165+ setOpen ,
166+ isMobile ,
167+ openMobile ,
168+ mobileSheetMounted ,
169+ setMobileSheetElement ,
170+ toggleSidebar ,
171+ ] ,
154172 ) ;
155173
156174 return (
157175 < SidebarContext value = { contextValue } >
158176 < div
159177 // Inset layouts opt into bg-sidebar through className.
160178 className = { cn (
161- "group/sidebar-wrapper flex min-h-svh w-full max-sm:[--workspace-titlebar-control-size:--spacing(8)]" ,
179+ "group/sidebar-wrapper flex min-h-svh w-full" ,
180+ SIDEBAR_TITLEBAR_CONTROL_SIZE ,
162181 className ,
163182 ) }
164183 data-sidebar-state = { state }
@@ -194,7 +213,7 @@ function Sidebar({
194213 collapsible ?: "offcanvas" | "icon" | "none" ;
195214 resizable ?: boolean | SidebarResizableOptions ;
196215} ) {
197- const { isMobile, state, openMobile, setOpenMobile } = useSidebar ( ) ;
216+ const { isMobile, state, openMobile, setOpenMobile, setMobileSheetElement } = useSidebar ( ) ;
198217 const resolvedResizable = React . useMemo < SidebarResolvedResizableOptions | null > ( ( ) => {
199218 if ( isMobile || collapsible === "none" || ! resizable ) {
200219 return null ;
@@ -236,6 +255,7 @@ function Sidebar({
236255 < SidebarInstanceContext value = { instanceContextValue } >
237256 < Sheet onOpenChange = { setOpenMobile } open = { openMobile } >
238257 < SheetPopup
258+ ref = { setMobileSheetElement }
239259 className = { cn (
240260 "w-(--sidebar-width) max-w-none bg-sidebar surface-grain p-0 text-sidebar-foreground" ,
241261 className ,
@@ -258,6 +278,7 @@ function Sidebar({
258278 < div
259279 className = { cn (
260280 "flex h-full w-full flex-col pb-safe pt-safe" ,
281+ SIDEBAR_TITLEBAR_CONTROL_SIZE ,
261282 side === "left" ? "pl-safe" : "pr-safe" ,
262283 ) }
263284 { ...props }
0 commit comments