@@ -436,9 +436,18 @@ export const GroupExpand = React.forwardRef<HTMLButtonElement, NavListGroupExpan
436
436
( { label = 'Show more' , pages = 0 , items, renderItem, ...props } , forwardedRef ) => {
437
437
const [ currentPage , setCurrentPage ] = React . useState ( 0 )
438
438
const groupId = useId ( )
439
+
439
440
const teamEnabled = useFeatureFlag ( 'primer_react_css_modules_team' )
440
441
const staffEnabled = useFeatureFlag ( 'primer_react_css_modules_staff' )
441
442
443
+ const calculateVisibleItems = React . useCallback ( ( ) => {
444
+ const itemsPerPage = items . length / pages
445
+ const amountToShow = pages === 0 ? items . length : Math . ceil ( itemsPerPage * currentPage )
446
+ const focusTargetIndex = currentPage === 1 ? 0 : amountToShow - Math . floor ( itemsPerPage )
447
+
448
+ return { amountToShow, focusTargetIndex}
449
+ } , [ pages , items , currentPage ] )
450
+
442
451
return (
443
452
< >
444
453
{ currentPage > 0 ? (
@@ -451,9 +460,7 @@ export const GroupExpand = React.forwardRef<HTMLButtonElement, NavListGroupExpan
451
460
trailingAction,
452
461
...rest
453
462
} = itemArr
454
- const itemsPerPage = items . length / pages
455
- const amountToShow = pages === 0 ? items . length : Math . ceil ( itemsPerPage * currentPage )
456
- const focusTargetIndex = currentPage === 1 ? 0 : amountToShow - Math . floor ( itemsPerPage )
463
+ const { amountToShow, focusTargetIndex} = calculateVisibleItems ( )
457
464
const focusTarget = index === focusTargetIndex ? groupId : 'false'
458
465
459
466
const { icon, label : actionLabel , ...props } = trailingAction || { }
@@ -473,14 +480,12 @@ export const GroupExpand = React.forwardRef<HTMLButtonElement, NavListGroupExpan
473
480
</ LeadingVisual >
474
481
) : null }
475
482
{ text }
476
- { ! trailingAction && TrailingVisualIcon ? (
483
+ { TrailingVisualIcon ? (
477
484
< TrailingVisual >
478
485
< TrailingVisualIcon />
479
486
</ TrailingVisual >
480
487
) : null }
481
- { ! TrailingVisualIcon && trailingAction ? (
482
- < TrailingAction icon = { icon } label = { actionLabel || '' } { ...props } />
483
- ) : null }
488
+ { trailingAction ? < TrailingAction icon = { icon } label = { actionLabel || '' } { ...props } /> : null }
484
489
</ Item >
485
490
)
486
491
}
0 commit comments