Skip to content

Commit 04fa5f5

Browse files
committed
Fix bug with hideRoot
1 parent d42ac5e commit 04fa5f5

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

packages/react/src/Breadcrumbs/Breadcrumbs.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
138138
currentMenuItems = itemsToHide
139139
currentVisibleItems = childArray.slice(childArray.length - 4)
140140
}
141-
141+
let eHideRoot = hideRoot
142142
// Now check if current visible items fit in available width
143143
if (availableWidth > 0) {
144144
let visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItems)
@@ -148,13 +148,11 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
148148
visibleItemsWidthTotal += MENU_BUTTON_WIDTH
149149
}
150150

151-
// Progressive hiding: keep moving items to menu until they fit
152-
let effectiveHideRoot = hideRoot
153151
while (visibleItemsWidthTotal > availableWidth && currentVisibleItems.length > 1) {
154152
// Determine which item to hide based on hideRoot setting
155153
let itemToHide: React.ReactElement
156154

157-
if (effectiveHideRoot) {
155+
if (eHideRoot) {
158156
// Hide from start when hideRoot is true
159157
itemToHide = currentVisibleItems[0]
160158
currentVisibleItems = currentVisibleItems.slice(1)
@@ -166,7 +164,6 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
166164

167165
currentMenuItems = [itemToHide, ...currentMenuItems]
168166

169-
// Recalculate width
170167
visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItems)
171168

172169
// Add menu button width
@@ -178,17 +175,15 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
178175
// fallback to hideRoot=true behavior (menu + leaf only)
179176
if (
180177
!hideRoot &&
181-
!effectiveHideRoot &&
178+
!eHideRoot &&
182179
currentVisibleItems.length === 2 &&
183180
visibleItemsWidthTotal > availableWidth
184181
) {
185-
effectiveHideRoot = true
186-
// Move the root item to menu as well
182+
eHideRoot = true
187183
const rootItem = currentVisibleItems[0]
188184
currentVisibleItems = currentVisibleItems.slice(1)
189185
currentMenuItems = [rootItem, ...currentMenuItems]
190186

191-
// Recalculate width one more time
192187
visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItems)
193188

194189
if (currentMenuItems.length > 0) {
@@ -197,21 +192,19 @@ function Breadcrumbs({className, children, sx: sxProp, overflow = 'wrap', hideRo
197192
}
198193
}
199194
}
200-
201195
return {
202196
visibleItems: currentVisibleItems,
203197
menuItems: currentMenuItems,
204-
effectiveHideRoot,
198+
effectiveHideRoot: eHideRoot,
205199
}
206200
}
207201

208-
// Apply the overflow calculation
209202
const result = calculateOverflow(containerWidth)
210203
setVisibleItems(result.visibleItems)
211204
setMenuItems(result.menuItems)
212205
setEffectiveHideRoot(result.effectiveHideRoot)
213206
}
214-
}, [childArray, overflow, containerWidth, hideRoot, itemWidths, effectiveHideRoot])
207+
}, [childArray, overflow, containerWidth, hideRoot, itemWidths])
215208

216209
// Determine final children to render
217210
const finalChildren = React.useMemo(() => {

0 commit comments

Comments
 (0)