File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ export default function RootLayout({ children }: { children: React.ReactNode })
153153 var expandedWidth =
154154 typeof width === 'number' && isFinite(width)
155155 ? Math.min(Math.max(width, 224), maxSidebarWidth)
156- : defaultSidebarWidth;
156+ : Math.min( defaultSidebarWidth, maxSidebarWidth) ;
157157 document.documentElement.style.setProperty(
158158 '--sidebar-expanded-width',
159159 expandedWidth + 'px'
Original file line number Diff line number Diff line change @@ -102,6 +102,21 @@ describe('sidebar width CSS variables', () => {
102102
103103 expect ( widthVars ( ) . expanded ) . toBe ( `${ SIDEBAR_WIDTH . MIN } px` )
104104 } )
105+
106+ it ( 'clamps the default fallback to a viewport maximum below the default' , ( ) => {
107+ const innerWidth = window . innerWidth
108+ window . innerWidth = 800
109+ try {
110+ useSidebarStore . setState ( { isCollapsed : false , sidebarWidth : Number . NaN } )
111+
112+ useSidebarStore . getState ( ) . syncWidth ( )
113+
114+ expect ( widthVars ( ) . expanded ) . toBe ( `${ getMaxSidebarWidth ( 800 ) } px` )
115+ expect ( getMaxSidebarWidth ( 800 ) ) . toBeLessThan ( SIDEBAR_WIDTH . DEFAULT )
116+ } finally {
117+ window . innerWidth = innerWidth
118+ }
119+ } )
105120} )
106121
107122describe ( 'getMaxSidebarWidth' , ( ) => {
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ export function getMaxSidebarWidth(viewportWidth: number): number {
2121
2222/** Clamps an expanded sidebar width into the valid range for the current viewport. */
2323function clampSidebarWidth ( width : number ) : number {
24- if ( ! Number . isFinite ( width ) ) return SIDEBAR_WIDTH . DEFAULT
24+ const target = Number . isFinite ( width ) ? width : SIDEBAR_WIDTH . DEFAULT
2525 const max =
2626 typeof window === 'undefined' ? Number . POSITIVE_INFINITY : getMaxSidebarWidth ( window . innerWidth )
27- return Math . min ( Math . max ( width , SIDEBAR_WIDTH . MIN ) , max )
27+ return Math . min ( Math . max ( target , SIDEBAR_WIDTH . MIN ) , max )
2828}
2929
3030/**
You can’t perform that action at this time.
0 commit comments