Skip to content

Commit e1a0426

Browse files
dongbanbanlihongxiangfrontend
authored andcommitted
fix: antd-issue-51248 (react-component#541)
* fix: antd-issue-51248 * feat: add test for 51248 * feat: update test for limit * feat: update test for limit * feat: update test for limit * feat: update test for limit
1 parent 2ad949e commit e1a0426

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

src/hooks/useSearchConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function useSearchConfig(showSearch?: CascaderProps['showSearch']
2222
}
2323

2424
if ((searchConfig.limit as number) <= 0) {
25-
delete searchConfig.limit;
25+
searchConfig.limit = false;
2626

2727
if (process.env.NODE_ENV !== 'production') {
2828
warning(false, "'limit' of showSearch should be positive number or false.");

tests/search.limit.spec.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import React from 'react';
2+
import Cascader from '../src';
3+
import type { ReactWrapper } from './enzyme';
4+
import { mount } from './enzyme';
5+
6+
describe('Cascader.Search', () => {
7+
function doSearch(wrapper: ReactWrapper, search: string) {
8+
wrapper.find('input').simulate('change', {
9+
target: {
10+
value: search,
11+
},
12+
});
13+
}
14+
const options = [
15+
{
16+
children: [] as any[],
17+
isParent: true,
18+
label: 'Asia',
19+
value: 'Asia',
20+
},
21+
];
22+
for (let i = 0; i < 100; i++) {
23+
options[0].children.push({
24+
label: 'label' + i,
25+
value: 'value' + i,
26+
});
27+
}
28+
29+
it('limit', () => {
30+
const wrapper = mount(
31+
<Cascader
32+
options={options}
33+
open
34+
showSearch={{
35+
limit: false,
36+
}}
37+
/>,
38+
);
39+
40+
doSearch(wrapper, 'as');
41+
const itemList = wrapper.find('div.rc-cascader-menu-item-content');
42+
expect(itemList).toHaveLength(100);
43+
});
44+
45+
it('limit', () => {
46+
const wrapper = mount(
47+
<Cascader
48+
options={options}
49+
open
50+
showSearch={{
51+
limit: 0,
52+
}}
53+
/>,
54+
);
55+
56+
doSearch(wrapper, 'as');
57+
const itemList = wrapper.find('div.rc-cascader-menu-item-content');
58+
expect(itemList).toHaveLength(100);
59+
});
60+
61+
it('limit', () => {
62+
const wrapper = mount(
63+
<Cascader
64+
options={options}
65+
open
66+
showSearch={{
67+
limit: 20,
68+
}}
69+
/>,
70+
);
71+
72+
doSearch(wrapper, 'as');
73+
const itemList = wrapper.find('div.rc-cascader-menu-item-content');
74+
expect(itemList).toHaveLength(20);
75+
});
76+
});

0 commit comments

Comments
 (0)