Skip to content

Commit b071e70

Browse files
committed
Tests are passing
1 parent a096e08 commit b071e70

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

packages/react/src/Breadcrumbs/Breadcrumbs.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
8383
const containerRef = useRef<HTMLElement>(null)
8484
const [effectiveHideRoot, setEffectiveHideRoot] = useState<boolean>(hideRoot)
8585
let effectiveOverflow = 'wrap'
86-
8786
const childArray = useMemo(() => getValidChildren(children), [children])
8887

8988
const rootItem = childArray[0]
@@ -94,7 +93,6 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
9493
const [menuItems, setMenuItems] = useState<React.ReactElement[]>([])
9594
const [rootItemWidth, setRootItemWidth] = useState<number>(0)
9695

97-
// SSR friendly
9896
if (typeof window !== 'undefined') {
9997
effectiveOverflow = overflow
10098
}
@@ -185,6 +183,18 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
185183

186184
useResizeObserver(handleResize, containerRef)
187185

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+
188198
// Determine final children to render
189199
const finalChildren = React.useMemo(() => {
190200
if (effectiveOverflow === 'wrap' || menuItems.length === 0) {

0 commit comments

Comments
 (0)