Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"@rc-component/trigger": "^2.1.1",
"classnames": "2.x",
"rc-motion": "^2.0.1",
"rc-overflow": "^1.3.1",
"rc-overflow": "^1.4.0",
"rc-util": "^5.16.1",
"rc-virtual-list": "^3.5.2"
},
Expand Down
1 change: 1 addition & 0 deletions src/BaseSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export type CustomTagProps = {
onClose: (event?: React.MouseEvent<HTMLElement, MouseEvent>) => void;
closable: boolean;
isMaxTag: boolean;
index?: number;
};

export interface BaseSelectRef {
Expand Down
14 changes: 12 additions & 2 deletions src/Selector/MultipleSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
closable?: boolean,
onClose?: React.MouseEventHandler,
isMaxTag?: boolean,
info?: { index: number },
) => {
const onMouseDown = (e: React.MouseEvent) => {
onPreventMouseDown(e);
Expand All @@ -141,6 +142,7 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
{tagRender({
label: content,
value,
index: info?.index,
disabled: itemDisabled,
closable,
onClose,
Expand All @@ -150,7 +152,7 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
);
};

const renderItem = (valueItem: DisplayValueType) => {
const renderItem = (valueItem: DisplayValueType, info: { index: number }) => {
const { disabled: itemDisabled, label, value } = valueItem;
const closable = !disabled && !itemDisabled;

Expand All @@ -173,7 +175,15 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
};

return typeof tagRender === 'function'
? customizeRenderSelector(value, displayLabel, itemDisabled, closable, onClose)
? customizeRenderSelector(
value,
displayLabel,
itemDisabled,
closable,
onClose,
undefined,
info,
)
: defaultRenderSelector(valueItem, displayLabel, itemDisabled, closable, onClose);
};

Expand Down
1 change: 1 addition & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface DisplayValueType {
label?: React.ReactNode;
title?: React.ReactNode;
disabled?: boolean;
index?: number;
}

export type RenderNode = React.ReactNode | ((props: any) => React.ReactNode);
Expand Down
22 changes: 22 additions & 0 deletions tests/Tags.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import removeSelectedTest from './shared/removeSelectedTest';
import maxTagRenderTest from './shared/maxTagRenderTest';
import throwOptionValue from './shared/throwOptionValue';
import { injectRunAllTimers, findSelection, expectOpen, toggleOpen, keyDown } from './utils/common';
import type { CustomTagProps } from '@/BaseSelect';

describe('Select.Tags', () => {
injectRunAllTimers(jest);
Expand Down Expand Up @@ -301,6 +302,27 @@ describe('Select.Tags', () => {
expectOpen(container, false);
});

it('tagRender props have index', () => {
const tagRender = (props: CustomTagProps) => {
const { index: tagIndex, label } = props;
return <div className={`${label}-${tagIndex}-test`}>{label}</div>;
};
const values = ['light', 'dark'];
const { container } = render(
<Select
mode="tags"
value={values}
tagRender={tagRender}
options={[{ value: 'light' }, { value: 'dark' }]}
/>,
);
values.forEach((value, index) => {
const expectedText = `.${value}-${index}-test`;
const nodes = container.querySelectorAll(expectedText);
expect(nodes).toHaveLength(1);
});
});

it('disabled', () => {
const tagRender = jest.fn();
render(
Expand Down