Skip to content

Commit 202ee82

Browse files
committed
feat: Support maxCount
1 parent b7071c9 commit 202ee82

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

examples/basic.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const Demo = () => {
5454
>
5555
<option value={0}>0</option>
5656
<option value={1}>1</option>
57+
<option value={2}>2</option>
5758
<option value={5}>5</option>
5859
<option value={10}>10</option>
5960
<option value={20}>20</option>

src/Overflow.tsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ function Overflow<ItemType = any>(
5454
if (isResponsive) {
5555
return data.slice(0, Math.min(data.length, containerWidth / itemWidth));
5656
}
57-
return data;
57+
return typeof maxCount === 'number' ? data.slice(0, maxCount) : data;
5858
}, [data, itemWidth, containerWidth, maxCount]);
5959

60+
// When is `responsive`, we will always render rest node to get the real width of it for calculation
61+
const showRest = isResponsive || data.length > maxCount!;
62+
6063
// ================================= Item =================================
6164
const getKey = React.useCallback(
6265
(item: ItemType, index: number) => {
@@ -154,16 +157,18 @@ function Overflow<ItemType = any>(
154157
})}
155158

156159
{/* Rest Count Item */}
157-
<Item
158-
order={displayCount}
159-
prefixCls={itemPrefixCls}
160-
className={`${itemPrefixCls}-rest`}
161-
responsive={isResponsive}
162-
registerSize={registerOverflowSize}
163-
display={restReady}
164-
>
165-
Overflow
166-
</Item>
160+
{showRest ? (
161+
<Item
162+
order={displayCount}
163+
prefixCls={itemPrefixCls}
164+
className={`${itemPrefixCls}-rest`}
165+
responsive={isResponsive}
166+
registerSize={registerOverflowSize}
167+
display={restReady && displayCount < data.length}
168+
>
169+
Overflow
170+
</Item>
171+
) : null}
167172
</div>
168173
);
169174

0 commit comments

Comments
 (0)