@@ -16,7 +16,7 @@ interface CollapsibleGroupProps {
1616
1717const GROUP_SX = { flexShrink : 0 , "& > *" : { flexShrink : 0 } } as const
1818
19- const KEY_SEPARATOR = "\u0000"
19+ const KEY_SEPARATOR = "\u0000" // joins item keys into comparable string
2020
2121export const CollapsibleGroup : React . FC < CollapsibleGroupProps > = ( { items, always } ) => {
2222 const fit = useTopBarFit ( )
@@ -26,6 +26,7 @@ export const CollapsibleGroup: React.FC<CollapsibleGroupProps> = ({ items, alway
2626 const itemCount = items . length
2727 const itemsKey = items . map ( item => item . key ) . join ( KEY_SEPARATOR )
2828
29+ // adding guard to ensure 'fitted' isn't stale during renders
2930 const [ fitted , setFitted ] = useState ( { itemsKey, visibleCount : itemCount } )
3031 if ( fitted . itemsKey !== itemsKey ) {
3132 widthsRef . current = [ ]
@@ -49,6 +50,7 @@ export const CollapsibleGroup: React.FC<CollapsibleGroupProps> = ({ items, alway
4950 const spacer = fit ?. spacerRef . current
5051 if ( ! row || ! spacer ) return
5152
53+ // width the items occupy; free space the flex spacer is taking rn; subtracting anything overflowing out of the row already
5254 const widths = widthsRef . current
5355 const usedByItems = widths . slice ( 0 , visibleCount ) . reduce ( ( total , width ) => total + width + TOP_BAR_GAP_PX , 0 )
5456 const overflow = Math . max ( 0 , row . scrollWidth - row . clientWidth )
0 commit comments