@@ -68,6 +68,12 @@ export type UsePaneWidthResult = {
6868 */
6969export const DEFAULT_MAX_WIDTH_DIFF = Number ( cssExports . paneMaxWidthDiffDefault )
7070
71+ /**
72+ * Default value for --sidebar-max-width-diff CSS variable.
73+ * Unlike --pane-max-width-diff, this is constant across all viewport sizes.
74+ */
75+ export const DEFAULT_SIDEBAR_MAX_WIDTH_DIFF = Number ( cssExports . sidebarMaxWidthDiffDefault )
76+
7177// --pane-max-width-diff changes at this breakpoint in PageLayout.module.css.
7278const DEFAULT_PANE_MAX_WIDTH_DIFF_BREAKPOINT = Number ( cssExports . paneMaxWidthDiffBreakpoint )
7379/**
@@ -106,14 +112,17 @@ export const getDefaultPaneWidth = (w: PaneWidthValue): number => {
106112}
107113
108114/**
109- * Gets the --pane-max-width-diff CSS variable value from a pane element.
110- * This value is set by CSS media queries and controls the max pane width constraint.
115+ * Gets the max-width-diff CSS variable value from a pane element.
116+ * For sidebars, reads --sidebar-max-width-diff (constant across viewports).
117+ * For panes, reads --pane-max-width-diff (changes at 1280px breakpoint).
111118 * Note: This calls getComputedStyle which forces layout - cache the result when possible.
112119 */
113- export function getPaneMaxWidthDiff ( paneElement : HTMLElement | null ) : number {
114- if ( ! paneElement ) return DEFAULT_MAX_WIDTH_DIFF
115- const value = parseInt ( getComputedStyle ( paneElement ) . getPropertyValue ( '--pane-max-width-diff' ) , 10 )
116- return value > 0 ? value : DEFAULT_MAX_WIDTH_DIFF
120+ export function getPaneMaxWidthDiff ( paneElement : HTMLElement | null , isSidebar = false ) : number {
121+ const defaultValue = isSidebar ? DEFAULT_SIDEBAR_MAX_WIDTH_DIFF : DEFAULT_MAX_WIDTH_DIFF
122+ const cssVar = isSidebar ? '--sidebar-max-width-diff' : '--pane-max-width-diff'
123+ if ( ! paneElement ) return defaultValue
124+ const value = parseInt ( getComputedStyle ( paneElement ) . getPropertyValue ( cssVar ) , 10 )
125+ return value > 0 ? value : defaultValue
117126}
118127
119128// Helper to update ARIA slider attributes via direct DOM manipulation
@@ -197,7 +206,7 @@ export function usePaneWidth({
197206 } )
198207 // Cache the CSS variable value to avoid getComputedStyle during drag (causes layout thrashing)
199208 // Updated on mount and resize when breakpoints might change
200- const maxWidthDiffRef = React . useRef ( DEFAULT_MAX_WIDTH_DIFF )
209+ const maxWidthDiffRef = React . useRef ( constrainToViewport ? DEFAULT_SIDEBAR_MAX_WIDTH_DIFF : DEFAULT_MAX_WIDTH_DIFF )
201210
202211 // Calculate max width constraint - for custom widths this is capped to viewport bounds
203212 // when constrainToViewport is set (e.g., Sidebar), otherwise it uses the custom max directly.
@@ -337,7 +346,7 @@ export function usePaneWidth({
337346 lastViewportWidth = currentViewportWidth
338347
339348 if ( crossedBreakpoint ) {
340- maxWidthDiffRef . current = getPaneMaxWidthDiff ( paneRef . current )
349+ maxWidthDiffRef . current = getPaneMaxWidthDiff ( paneRef . current , constrainToViewport )
341350 }
342351
343352 const actualMax = getMaxPaneWidthRef . current ( )
@@ -365,7 +374,7 @@ export function usePaneWidth({
365374 }
366375
367376 // Initial calculation on mount
368- maxWidthDiffRef . current = getPaneMaxWidthDiff ( paneRef . current )
377+ maxWidthDiffRef . current = getPaneMaxWidthDiff ( paneRef . current , constrainToViewport )
369378 const initialMax = getMaxPaneWidthRef . current ( )
370379 setMaxPaneWidth ( initialMax )
371380 paneRef . current ?. style . setProperty ( '--pane-max-width' , `${ initialMax } px` )
0 commit comments