@@ -103,28 +103,16 @@ function syncHeaderOverflow() {
103103 allButtons . forEach ( ( btn ) => btn . classList . remove ( 'is-overflowed' ) ) ;
104104
105105 // Hide overflow button initially to measure without it
106- if ( overflowBtn ) {
107- overflowBtn . style . display = 'none' ;
108- }
106+ if ( overflowBtn ) overflowBtn . style . display = 'none' ;
109107
110108 // Force layout settle to get accurate measurements
111109 void header . offsetWidth ;
112110 void main . offsetWidth ;
113111
114- // Get actual measurements after reset
115- const headerRect = header . getBoundingClientRect ( ) ;
116- const logoContainer = header . querySelector ( 'div:first-child' ) ;
117- const logoRect = logoContainer ? logoContainer . getBoundingClientRect ( ) : { width : 0 } ;
118-
119- // Get computed styles for padding
120- const headerStyles = window . getComputedStyle ( header ) ;
121- const paddingLeft = parseFloat ( headerStyles . paddingLeft ) || 0 ;
122- const paddingRight = parseFloat ( headerStyles . paddingRight ) || 0 ;
112+ // Measure on the actions container to avoid over-subtracting
113+ const actionsRect = headerActions . getBoundingClientRect ( ) ;
123114 const gap = 8 ; // gap between elements (0.5rem = 8px)
124115
125- // Calculate space taken by logo and gaps
126- const logoWithGap = logoRect . width + gap ;
127-
128116 // Measure all button widths
129117 let totalButtonsWidth = 0 ;
130118 const buttonWidths = [ ] ;
@@ -140,8 +128,8 @@ function syncHeaderOverflow() {
140128 totalButtonsWidth -= gap ;
141129 }
142130
143- // Calculate available width: full header width minus logo, padding, and gaps
144- const availableWidthWithoutOverflow = headerRect . width - logoWithGap - paddingLeft - paddingRight ;
131+ // Available width is the width of the actions container
132+ const availableWidthWithoutOverflow = actionsRect . width ;
145133
146134 // First check: do all buttons fit without overflow button?
147135 if ( totalButtonsWidth <= availableWidthWithoutOverflow ) {
@@ -154,28 +142,20 @@ function syncHeaderOverflow() {
154142
155143 // Buttons don't all fit - we need the overflow button
156144 const overflowBtnWidth = overflowBtn ? ( overflowBtn . getBoundingClientRect ( ) . width || 80 ) + gap : 80 + gap ;
157- const availableWidthWithOverflow = headerRect . width - logoWithGap - overflowBtnWidth - paddingLeft - paddingRight ;
145+ const availableWidthWithOverflow = actionsRect . width - overflowBtnWidth ;
158146
159147 // Now calculate what fits: pinned buttons always show, then fit overflowable from left
160148 let currentWidth = 0 ;
161149
162- // Add pinned buttons first
150+ // Add pinned buttons first (none currently, but keep logic)
163151 pinnedButtons . forEach ( ( btn ) => {
164152 const item = buttonWidths . find ( b => b . btn === btn ) ;
165- if ( item ) {
166- currentWidth += item . width + gap ;
167- }
153+ if ( item ) currentWidth += item . width + gap ;
168154 } ) ;
169-
170- // Subtract gap after last pinned button if there are overflowable buttons
171- if ( pinnedButtons . length > 0 && overflowableButtons . length > 0 ) {
172- currentWidth -= gap ; // Remove the gap, we'll add it between sections if needed
173- }
174-
155+ if ( pinnedButtons . length > 0 && overflowableButtons . length > 0 ) currentWidth -= gap ;
156+
175157 // Show overflow button since we need it
176- if ( overflowBtn ) {
177- overflowBtn . style . display = '' ;
178- }
158+ if ( overflowBtn ) overflowBtn . style . display = '' ;
179159
180160 // Now fit overflowable buttons from left to right
181161 let overflowCount = 0 ;
@@ -196,14 +176,8 @@ function syncHeaderOverflow() {
196176 }
197177
198178 // Show divider only if there are overflow items
199- if ( overflowDivider ) {
200- overflowDivider . style . display = overflowCount > 0 ? 'block' : 'none' ;
201- }
202-
203- // If no buttons in overflow, hide the overflow button
204- if ( overflowCount === 0 && overflowBtn ) {
205- overflowBtn . style . display = 'none' ;
206- }
179+ if ( overflowDivider ) overflowDivider . style . display = overflowCount > 0 ? 'block' : 'none' ;
180+ if ( overflowCount === 0 && overflowBtn ) overflowBtn . style . display = 'none' ;
207181}
208182
209183// Close dropdown when clicking outside
0 commit comments