@@ -83,7 +83,6 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
83
83
const containerRef = useRef < HTMLElement > ( null )
84
84
const [ effectiveHideRoot , setEffectiveHideRoot ] = useState < boolean > ( hideRoot )
85
85
let effectiveOverflow = 'wrap'
86
-
87
86
const childArray = useMemo ( ( ) => getValidChildren ( children ) , [ children ] )
88
87
89
88
const rootItem = childArray [ 0 ]
@@ -94,7 +93,6 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
94
93
const [ menuItems , setMenuItems ] = useState < React . ReactElement [ ] > ( [ ] )
95
94
const [ rootItemWidth , setRootItemWidth ] = useState < number > ( 0 )
96
95
97
- // SSR friendly
98
96
if ( typeof window !== 'undefined' ) {
99
97
effectiveOverflow = overflow
100
98
}
@@ -185,6 +183,18 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
185
183
186
184
useResizeObserver ( handleResize , containerRef )
187
185
186
+ // Initial overflow calculation for testing and >5 items
187
+ useEffect ( ( ) => {
188
+ if ( overflow === 'menu' && childArray . length > 5 ) {
189
+ // Get actual container width from DOM or use default
190
+ const containerWidth = containerRef . current ?. offsetWidth || 800
191
+ const result = calculateOverflow ( containerWidth )
192
+ setVisibleItems ( result . visibleItems )
193
+ setMenuItems ( result . menuItems )
194
+ setEffectiveHideRoot ( result . effectiveHideRoot )
195
+ }
196
+ } , [ overflow , childArray . length , calculateOverflow ] )
197
+
188
198
// Determine final children to render
189
199
const finalChildren = React . useMemo ( ( ) => {
190
200
if ( effectiveOverflow === 'wrap' || menuItems . length === 0 ) {
0 commit comments