@@ -30,23 +30,33 @@ function Overflow<ItemType = any>(
3030 itemWidth = 10 ,
3131 style,
3232 className,
33- maxCount = RESPONSIVE ,
33+ maxCount,
3434 } = props ;
3535
3636 const createUseState = useBatchFrameState ( ) ;
37- const disabled = maxCount !== RESPONSIVE ;
37+ // const disabled = maxCount !== RESPONSIVE;
3838
3939 const [ containerWidth , setContainerWidth ] = createUseState ( 0 ) ;
4040 const [ itemWidths , setItemWidths ] = createUseState (
4141 new Map < React . Key , number > ( ) ,
4242 ) ;
43- const [ overflowWidth , setOverflowWidth ] = createUseState ( 0 ) ;
43+ const [ restWidth , setRestWidth ] = createUseState ( 0 ) ;
4444
4545 const [ displayCount , setDisplayCount ] = React . useState ( 0 ) ;
4646 const [ restReady , setRestReady ] = React . useState ( false ) ;
4747
4848 const itemPrefixCls = `${ prefixCls } -item` ;
4949
50+ // ================================= Data =================================
51+ const isResponsive = maxCount === RESPONSIVE ;
52+
53+ const mergedData = React . useMemo ( ( ) => {
54+ if ( isResponsive ) {
55+ return data . slice ( 0 , Math . min ( data . length , containerWidth / itemWidth ) ) ;
56+ }
57+ return data ;
58+ } , [ data , itemWidth , containerWidth , maxCount ] ) ;
59+
5060 // ================================= Item =================================
5161 const getKey = React . useCallback (
5262 ( item : ItemType , index : number ) => {
@@ -89,18 +99,12 @@ function Overflow<ItemType = any>(
8999 }
90100
91101 function registerOverflowSize ( _ : React . Key , width : number ) {
92- setOverflowWidth ( width ) ;
102+ setRestWidth ( width ) ;
93103 }
94104
95- // ================================= Data =================================
96- const mergedData = React . useMemo (
97- ( ) => data . slice ( 0 , Math . min ( data . length , containerWidth / itemWidth ) ) ,
98- [ data , itemWidth , containerWidth ] ,
99- ) ;
100-
101105 // ================================ Effect ================================
102106 React . useLayoutEffect ( ( ) => {
103- if ( containerWidth && overflowWidth && mergedData ) {
107+ if ( containerWidth && restWidth && mergedData ) {
104108 let totalWidth = 0 ;
105109
106110 const len = mergedData . length ;
@@ -117,7 +121,7 @@ function Overflow<ItemType = any>(
117121 // Find best match
118122 totalWidth += currentItemWidth ;
119123
120- if ( totalWidth + overflowWidth > containerWidth ) {
124+ if ( totalWidth + restWidth > containerWidth ) {
121125 updateDisplayCount ( i - 1 ) ;
122126 break ;
123127 } else if ( i === len - 1 ) {
@@ -126,7 +130,7 @@ function Overflow<ItemType = any>(
126130 }
127131 }
128132 }
129- } , [ containerWidth , itemWidths , overflowWidth , getKey , mergedData ] ) ;
133+ } , [ containerWidth , itemWidths , restWidth , getKey , mergedData ] ) ;
130134
131135 // ================================ Render ================================
132136 let overflowNode = (
@@ -143,7 +147,7 @@ function Overflow<ItemType = any>(
143147 renderItem = { mergedRenderItem }
144148 itemKey = { key }
145149 registerSize = { registerSize }
146- disabled = { disabled }
150+ responsive = { isResponsive }
147151 display = { index <= displayCount }
148152 />
149153 ) ;
@@ -154,7 +158,7 @@ function Overflow<ItemType = any>(
154158 order = { displayCount }
155159 prefixCls = { itemPrefixCls }
156160 className = { `${ itemPrefixCls } -rest` }
157- disabled = { disabled }
161+ responsive = { isResponsive }
158162 registerSize = { registerOverflowSize }
159163 display = { restReady }
160164 >
@@ -163,7 +167,7 @@ function Overflow<ItemType = any>(
163167 </ div >
164168 ) ;
165169
166- if ( ! disabled ) {
170+ if ( isResponsive ) {
167171 overflowNode = (
168172 < ResizeObserver onResize = { onOverflowResize } >
169173 { overflowNode }
0 commit comments