Skip to content

Commit 74969b0

Browse files
authored
fix: tagRender should work on max tag (#1044)
* fix: tagRender should work on max tag * chore: update @type/jest * chore: fix lint and tsc errors
1 parent d905f98 commit 74969b0

16 files changed

+67
-36
lines changed

docs/examples/filterSort.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const Test = () => (
2222
filterSort={sorterByLabel}
2323
optionFilterProp="label"
2424
options={incidencesStateResource}
25-
></Select>
25+
/>
2626
<h3> without filter sort </h3>
2727
<Select
2828
showSearch

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
},
5656
"devDependencies": {
5757
"@rc-component/father-plugin": "^1.0.2",
58-
"@testing-library/jest-dom": "^5.16.5",
59-
"@testing-library/react": "^13.0.0",
60-
"@types/jest": "^26.0.24",
58+
"@testing-library/jest-dom": "^6.4.5",
59+
"@testing-library/react": "^15.0.6",
60+
"@types/jest": "^29.5.12",
6161
"@types/react": "^18.2.45",
6262
"@types/react-dom": "^18.2.18",
6363
"babel-jest": "^29.6.1",

src/BaseSelect.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type CustomTagProps = {
6767
disabled: boolean;
6868
onClose: (event?: React.MouseEvent<HTMLElement, MouseEvent>) => void;
6969
closable: boolean;
70+
isMaxTag: boolean;
7071
};
7172

7273
export interface BaseSelectRef {

src/Selector/MultipleSelector.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,17 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
128128
value: RawValueType,
129129
content: React.ReactNode,
130130
itemDisabled: boolean,
131-
closable: boolean,
132-
onClose: React.MouseEventHandler,
131+
closable?: boolean,
132+
onClose?: React.MouseEventHandler,
133+
isMaxTag?: boolean,
133134
) => {
134135
const onMouseDown = (e: React.MouseEvent) => {
135136
onPreventMouseDown(e);
136137
onToggleOpen(!open);
137138
};
138139
return (
139140
<span onMouseDown={onMouseDown}>
140-
{tagRender({ label: content, value, disabled: itemDisabled, closable, onClose })}
141+
{tagRender({ label: content, value, disabled: itemDisabled, closable, onClose, isMaxTag: !!isMaxTag })}
141142
</span>
142143
);
143144
};
@@ -174,8 +175,9 @@ const SelectSelector: React.FC<SelectorProps> = (props) => {
174175
typeof maxTagPlaceholder === 'function'
175176
? maxTagPlaceholder(omittedValues)
176177
: maxTagPlaceholder;
177-
178-
return defaultRenderSelector({ title: content }, content, false);
178+
return typeof tagRender === 'function'
179+
? customizeRenderSelector(undefined, content, false, false, undefined, true)
180+
: defaultRenderSelector({ title: content }, content, false);
179181
};
180182

181183
// >>> Input Node

tests/BaseSelect.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { OptionListProps, RefOptionListProps } from '@/OptionList';
2-
import { act, fireEvent, render } from '@testing-library/react';
3-
import { forwardRef } from 'react';
2+
import { fireEvent, render } from '@testing-library/react';
3+
import { forwardRef, act } from 'react';
44
import BaseSelect from '../src/BaseSelect';
55

66
const OptionList = forwardRef<RefOptionListProps, OptionListProps>(() => (

tests/Combobox.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/* eslint-disable max-classes-per-file */
22

33
import '@testing-library/jest-dom';
4-
import { act, fireEvent, render } from '@testing-library/react';
4+
import { fireEvent, render } from '@testing-library/react';
55
import KeyCode from 'rc-util/lib/KeyCode';
66
import { resetWarned } from 'rc-util/lib/warning';
7-
import React from 'react';
7+
import React, { act } from 'react';
88
import type { SelectProps } from '../src';
99
import Select, { Option } from '../src';
1010
import allowClearTest from './shared/allowClearTest';

tests/Field.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { act } from 'react-dom/test-utils';
2-
import * as React from 'react';
1+
import React, { act } from 'react';
32
import Select from '../src';
43
import type { SelectProps } from '../src';
54
import { injectRunAllTimers } from './utils/common';

tests/Multiple.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Select, { Option, OptGroup } from '../src';
44
import focusTest from './shared/focusTest';
55
import blurTest from './shared/blurTest';
66
import hoverTest from './shared/hoverTest';
7-
import renderTest from './shared/renderTest';
7+
import maxTagRenderTest from './shared/maxTagRenderTest';
88
import removeSelectedTest from './shared/removeSelectedTest';
99
import dynamicChildrenTest from './shared/dynamicChildrenTest';
1010
import inputFilterTest from './shared/inputFilterTest';
@@ -27,7 +27,7 @@ describe('Select.Multiple', () => {
2727
focusTest('multiple');
2828
blurTest('multiple');
2929
hoverTest('multiple');
30-
renderTest('multiple');
30+
maxTagRenderTest('multiple');
3131
removeSelectedTest('multiple');
3232
dynamicChildrenTest('multiple');
3333
inputFilterTest('multiple');

tests/OptionList.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import KeyCode from 'rc-util/lib/KeyCode';
2-
import React from 'react';
3-
import { act } from 'react-dom/test-utils';
2+
import React, { act } from 'react';
43
import { BaseSelectContext } from '../src/hooks/useBaseProps';
54
import type { RefOptionListProps } from '../src/OptionList';
65
import OptionList from '../src/OptionList';

tests/Select.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import KeyCode from 'rc-util/lib/KeyCode';
44
import { spyElementPrototypes } from 'rc-util/lib/test/domHook';
55
import { resetWarned } from 'rc-util/lib/warning';
66
import type { ScrollConfig } from 'rc-virtual-list/lib/List';
7-
import React from 'react';
8-
import { act } from 'react-dom/test-utils';
7+
import React, { act } from 'react';
98
import type { SelectProps } from '../src';
109
import Select, { OptGroup, Option, useBaseProps } from '../src';
1110
import type { BaseSelectRef } from '../src/BaseSelect';

0 commit comments

Comments
 (0)