diff --git a/examples/fill-width.tsx b/examples/fill-width.tsx
index 5dd6407..38c7a24 100644
--- a/examples/fill-width.tsx
+++ b/examples/fill-width.tsx
@@ -112,6 +112,7 @@ const Demo = () => {
renderItem={renderItem}
renderRest={renderRest}
maxCount={responsive ? 'responsive' : 6}
+ prefix={Foobar}
suffix={
extends React.HTMLAttributes
{
+export interface OverflowProps extends Omit, 'prefix'> {
prefixCls?: string;
className?: string;
style?: React.CSSProperties;
@@ -33,6 +33,7 @@ export interface OverflowProps extends React.HTMLAttributes {
| ((omittedItems: ItemType[]) => React.ReactNode);
/** @private Do not use in your production. Render raw node that need wrap Item by developer self */
renderRawRest?: (omittedItems: ItemType[]) => React.ReactElement;
+ prefix?: React.ReactNode;
suffix?: React.ReactNode;
component?: ComponentType;
itemComponent?: ComponentType;
@@ -65,6 +66,7 @@ function Overflow(
maxCount,
renderRest,
renderRawRest,
+ prefix,
suffix,
component: Component = 'div',
itemComponent,
@@ -96,6 +98,11 @@ function Overflow(
0,
);
+ const [prefixWidth, setPrefixWidth] = useEffectState(
+ notifyEffectUpdate,
+ 0,
+ );
+
const [suffixWidth, setSuffixWidth] = useEffectState(
notifyEffectUpdate,
0,
@@ -223,6 +230,10 @@ function Overflow(
setPrevRestWidth(restWidth);
}
+ function registerPrefixSize(_: React.Key, width: number | null) {
+ setPrefixWidth(width!);
+ }
+
function registerSuffixSize(_: React.Key, width: number | null) {
setSuffixWidth(width!);
}
@@ -238,7 +249,7 @@ function Overflow(
typeof mergedRestWidth === 'number' &&
mergedData
) {
- let totalWidth = suffixWidth;
+ let totalWidth = prefixWidth + suffixWidth;
const len = mergedData.length;
const lastIndex = len - 1;
@@ -286,7 +297,7 @@ function Overflow(
}
}
- if (suffix && getItemWidth(0) + suffixWidth > mergedContainerWidth) {
+ if (suffix && getItemWidth(0) + suffixWidth + prefixWidth > mergedContainerWidth) {
setSuffixFixedStart(null);
}
}
@@ -294,6 +305,7 @@ function Overflow(
mergedContainerWidth,
itemWidths,
restWidth,
+ prefixWidth,
suffixWidth,
getKey,
mergedData,
@@ -366,26 +378,26 @@ function Overflow(
const mergedRenderRest = renderRest || defaultRenderRest;
- const restNode = renderRawRest ? (
-
- {renderRawRest(omittedItems)}
-
- ) : (
- -
- {typeof mergedRenderRest === 'function'
- ? mergedRenderRest(omittedItems)
- : mergedRenderRest}
-
- );
+ const restNode = renderRawRest ? (
+
+ {renderRawRest(omittedItems)}
+
+ ) : (
+ -
+ {typeof mergedRenderRest === 'function'
+ ? mergedRenderRest(omittedItems)
+ : mergedRenderRest}
+
+ );
const overflowNode = (
(
ref={ref}
{...restProps}
>
+ {/* Prefix Node */}
+ {prefix && (
+ -
+ {prefix}
+
+ )}
{mergedData.map(internalRenderItemNode)}
{/* Rest Count Item */}
@@ -421,7 +447,9 @@ function Overflow(
{overflowNode}
- ) : overflowNode;
+ ) : (
+ overflowNode
+ );
}
const ForwardOverflow = React.forwardRef(Overflow);