@@ -10,7 +10,6 @@ import {useResizeObserver} from '../hooks/useResizeObserver'
1010import type { ResizeObserverEntry } from '../hooks/useResizeObserver'
1111import { useOnEscapePress } from '../hooks/useOnEscapePress'
1212import { useOnOutsideClick } from '../hooks/useOnOutsideClick'
13- import { useFeatureFlag } from '../FeatureFlags'
1413
1514export type BreadcrumbsProps = React . PropsWithChildren < {
1615 /**
@@ -145,8 +144,6 @@ const getValidChildren = (children: React.ReactNode) => {
145144}
146145
147146function Breadcrumbs ( { className, children, style, overflow = 'wrap' , variant = 'normal' } : BreadcrumbsProps ) {
148- const overflowMenuEnabled = useFeatureFlag ( 'primer_react_breadcrumbs_overflow_menu' )
149- const wrappedChildren = React . Children . map ( children , child => < li className = { classes . ItemWrapper } > { child } </ li > )
150147 const containerRef = useRef < HTMLElement > ( null )
151148
152149 const measureMenuButton = useCallback ( ( element : HTMLDetailsElement | null ) => {
@@ -176,18 +173,13 @@ function Breadcrumbs({className, children, style, overflow = 'wrap', variant = '
176173
177174 useEffect ( ( ) => {
178175 const listElement = containerRef . current ?. querySelector ( 'ol' )
179- if (
180- overflowMenuEnabled &&
181- listElement &&
182- listElement . children . length > 0 &&
183- listElement . children . length === childArray . length
184- ) {
176+ if ( listElement && listElement . children . length > 0 && listElement . children . length === childArray . length ) {
185177 const listElementArray = Array . from ( listElement . children ) as HTMLElement [ ]
186178 const widths = listElementArray . map ( child => child . offsetWidth )
187179 setChildArrayWidths ( widths )
188180 setRootItemWidth ( listElementArray [ 0 ] . offsetWidth )
189181 }
190- } , [ childArray , overflowMenuEnabled ] )
182+ } , [ childArray ] )
191183
192184 const calculateOverflow = useCallback (
193185 ( availableWidth : number ) => {
@@ -247,7 +239,7 @@ function Breadcrumbs({className, children, style, overflow = 'wrap', variant = '
247239
248240 const handleResize = useCallback (
249241 ( entries : ResizeObserverEntry [ ] ) => {
250- if ( overflowMenuEnabled && entries [ 0 ] ) {
242+ if ( entries [ 0 ] ) {
251243 const containerWidth = entries [ 0 ] . contentRect . width
252244 const result = calculateOverflow ( containerWidth )
253245 if (
@@ -260,73 +252,66 @@ function Breadcrumbs({className, children, style, overflow = 'wrap', variant = '
260252 }
261253 }
262254 } ,
263- [ calculateOverflow , effectiveHideRoot , menuItems . length , overflowMenuEnabled , visibleItems . length ] ,
255+ [ calculateOverflow , effectiveHideRoot , menuItems . length , visibleItems . length ] ,
264256 )
265257
266258 useResizeObserver ( handleResize , containerRef )
267259
268260 useEffect ( ( ) => {
269- if (
270- overflowMenuEnabled &&
271- ( overflow === 'menu' || overflow === 'menu-with-root' ) &&
272- childArray . length > 5 &&
273- menuItems . length === 0
274- ) {
261+ if ( ( overflow === 'menu' || overflow === 'menu-with-root' ) && childArray . length > 5 && menuItems . length === 0 ) {
275262 const containerWidth = containerRef . current ?. offsetWidth || 800
276263 const result = calculateOverflow ( containerWidth )
277264 setVisibleItems ( result . visibleItems )
278265 setMenuItems ( result . menuItems )
279266 setEffectiveHideRoot ( result . effectiveHideRoot )
280267 }
281- } , [ overflow , childArray , calculateOverflow , menuItems . length , overflowMenuEnabled ] )
268+ } , [ overflow , childArray , calculateOverflow , menuItems . length ] )
282269
283270 const finalChildren = React . useMemo ( ( ) => {
284- if ( overflowMenuEnabled ) {
285- if ( overflow === 'wrap' || menuItems . length === 0 ) {
286- return React . Children . map ( children , child => < li className = { classes . ItemWrapper } > { child } </ li > )
287- }
271+ if ( overflow === 'wrap' || menuItems . length === 0 ) {
272+ return React . Children . map ( children , child => < li className = { classes . ItemWrapper } > { child } </ li > )
273+ }
288274
289- let effectiveMenuItems = [ ...menuItems ]
290- // In 'menu-with-root' mode, include the root item inside the menu even if it's visible in the breadcrumbs
291- if ( ! effectiveHideRoot ) {
292- effectiveMenuItems = [ ...menuItems . slice ( 1 ) ]
293- }
294- const menuElement = (
295- < li className = { classes . BreadcrumbsItem } key = "breadcrumbs-menu" >
296- < BreadcrumbsMenuItem
297- ref = { measureMenuButton }
298- items = { effectiveMenuItems }
299- aria-label = { `${ effectiveMenuItems . length } more breadcrumb items` }
300- />
301- < ItemSeparator />
302- </ li >
303- )
304-
305- const visibleElements = visibleItems . map ( ( child , index ) => (
306- < li className = { classes . BreadcrumbsItem } key = { `visible + ${ index } ` } >
307- { child }
308- < ItemSeparator />
309- </ li >
310- ) )
311-
312- const rootElement = (
313- < li className = { classes . BreadcrumbsItem } key = { `rootElement` } >
314- { rootItem }
315- < ItemSeparator />
316- </ li >
317- )
318-
319- if ( effectiveHideRoot ) {
320- // Show: [overflow menu, leaf breadcrumb]
321- return [ menuElement , ...visibleElements ]
322- } else {
323- // Show: [root breadcrumb, overflow menu, leaf breadcrumb]
324- return [ rootElement , menuElement , ...visibleElements ]
325- }
275+ let effectiveMenuItems = [ ...menuItems ]
276+ // In 'menu-with-root' mode, include the root item inside the menu even if it's visible in the breadcrumbs
277+ if ( ! effectiveHideRoot ) {
278+ effectiveMenuItems = [ ...menuItems . slice ( 1 ) ]
279+ }
280+ const menuElement = (
281+ < li className = { classes . BreadcrumbsItem } key = "breadcrumbs-menu" >
282+ < BreadcrumbsMenuItem
283+ ref = { measureMenuButton }
284+ items = { effectiveMenuItems }
285+ aria-label = { `${ effectiveMenuItems . length } more breadcrumb items` }
286+ />
287+ < ItemSeparator />
288+ </ li >
289+ )
290+
291+ const visibleElements = visibleItems . map ( ( child , index ) => (
292+ < li className = { classes . BreadcrumbsItem } key = { `visible + ${ index } ` } >
293+ { child }
294+ < ItemSeparator />
295+ </ li >
296+ ) )
297+
298+ const rootElement = (
299+ < li className = { classes . BreadcrumbsItem } key = { `rootElement` } >
300+ { rootItem }
301+ < ItemSeparator />
302+ </ li >
303+ )
304+
305+ if ( effectiveHideRoot ) {
306+ // Show: [overflow menu, leaf breadcrumb]
307+ return [ menuElement , ...visibleElements ]
308+ } else {
309+ // Show: [root breadcrumb, overflow menu, leaf breadcrumb]
310+ return [ rootElement , menuElement , ...visibleElements ]
326311 }
327- } , [ overflowMenuEnabled , overflow , menuItems , effectiveHideRoot , measureMenuButton , visibleItems , rootItem , children ] )
312+ } , [ overflow , menuItems , effectiveHideRoot , measureMenuButton , visibleItems , rootItem , children ] )
328313
329- return overflowMenuEnabled ? (
314+ return (
330315 < nav
331316 className = { clsx ( className , classes . BreadcrumbsBase ) }
332317 aria-label = "Breadcrumbs"
@@ -337,15 +322,6 @@ function Breadcrumbs({className, children, style, overflow = 'wrap', variant = '
337322 >
338323 < BreadcrumbsList > { finalChildren } </ BreadcrumbsList >
339324 </ nav >
340- ) : (
341- < nav
342- className = { clsx ( className , classes . BreadcrumbsBase ) }
343- aria-label = "Breadcrumbs"
344- style = { style }
345- data-variant = { variant }
346- >
347- < BreadcrumbsList > { wrappedChildren } </ BreadcrumbsList >
348- </ nav >
349325 )
350326}
351327
0 commit comments