@@ -39,6 +39,8 @@ function Overflow<ItemType = any>(
3939 ) ;
4040 const [ overflowWidth , setOverflowWidth ] = createUseState ( 0 ) ;
4141
42+ const [ displayCount , setDisplayCount ] = React . useState ( 0 ) ;
43+
4244 const itemPrefixCls = `${ prefixCls } -item` ;
4345
4446 // ================================= Item =================================
@@ -79,6 +81,27 @@ function Overflow<ItemType = any>(
7981 setOverflowWidth ( width ) ;
8082 }
8183
84+ // ================================ Effect ================================
85+ React . useLayoutEffect ( ( ) => {
86+ console . log ( 'Effect >>>' , containerWidth , itemWidths , overflowWidth ) ;
87+ if ( containerWidth && overflowWidth && data ) {
88+ let totalWidth = 0 ;
89+
90+ const len = data . length ;
91+
92+ for ( let i = 0 ; i < len ; i += 1 ) {
93+ const itemWidth = itemWidths . get ( getKey ( data [ i ] , i ) ) || 0 ;
94+ totalWidth += itemWidth ;
95+
96+ if ( totalWidth + overflowWidth > containerWidth ) {
97+ setDisplayCount ( i - 1 ) ;
98+ } else if ( i === len - 1 ) {
99+ setDisplayCount ( len - 1 ) ;
100+ }
101+ }
102+ }
103+ } , [ containerWidth , itemWidths , overflowWidth , getKey , data ] ) ;
104+
82105 // ================================ Render ================================
83106 let overflowNode = (
84107 < div className = { classNames ( prefixCls , className ) } style = { style } ref = { ref } >
@@ -94,6 +117,7 @@ function Overflow<ItemType = any>(
94117 itemKey = { key }
95118 registerSize = { registerSize }
96119 disabled = { disabled }
120+ display = { index <= displayCount }
97121 />
98122 ) ;
99123 } ) }
0 commit comments