Skip to content

Commit

Permalink
feat:修改index赋值节点
Browse files Browse the repository at this point in the history
  • Loading branch information
刘欢 committed Jan 7, 2025
1 parent a25df5a commit a2e4470
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import * as React from 'react';
import classNames from 'classnames';
import ResizeObserver from 'rc-resize-observer';
import type { ItemWithIndex } from './Overflow';
import type { ComponentType } from './RawItem';

// Use shared variable to save bundle size
const UNDEFINED = undefined;

export interface ItemProps<ItemType> extends React.HTMLAttributes<any> {
prefixCls: string;
item?: ItemType;
item?: ItemWithIndex<ItemType>;
className?: string;
style?: React.CSSProperties;
renderItem?: (item: ItemType) => React.ReactNode;
renderItem?: (item: ItemWithIndex<ItemType>) => React.ReactNode;
responsive?: boolean;
// https://github.com/ant-design/ant-design/issues/35475
/**
Expand Down
8 changes: 5 additions & 3 deletions src/Overflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export { OverflowContext } from './context';

export type { ComponentType } from './RawItem';

export type ItemWithIndex<ItemType> = ItemType & { index?: number };

export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
prefixCls?: string;
className?: string;
Expand All @@ -24,7 +26,7 @@ export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
itemKey?: React.Key | ((item: ItemType) => React.Key);
/** Used for `responsive`. It will limit render node to avoid perf issue */
itemWidth?: number;
renderItem?: (item: ItemType) => React.ReactNode;
renderItem?: (item: ItemWithIndex<ItemType>) => React.ReactNode;
/** @private Do not use in your production. Render raw node that need wrap Item by developer self */
renderRawItem?: (item: ItemType, index: number) => React.ReactElement;
maxCount?: number | typeof RESPONSIVE | typeof INVALIDATE;
Expand Down Expand Up @@ -341,13 +343,13 @@ function Overflow<ItemType = any>(
}
: (item: ItemType, index: number) => {
const key = getKey(item, index);

const propsItem: ItemWithIndex<ItemType> = { ...item, index };
return (
<Item
{...itemSharedProps}
order={index}
key={key}
item={{ ...item, index }}
item={propsItem}
renderItem={mergedRenderItem}
itemKey={key}
registerSize={registerSize}
Expand Down
4 changes: 2 additions & 2 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ describe('Overflow.Basic', () => {
const wrapper = mount(
<Overflow
data={testData}
renderItem={(item, order) => {
return `${item.label}-${order}-test`;
renderItem={(item) => {
return `${item.label}-${item.index}-test`;
}}
/>,
);
Expand Down

0 comments on commit a2e4470

Please sign in to comment.