Skip to content

Commit 124d7c9

Browse files
committed
feat: update test for limit
1 parent 9c2b525 commit 124d7c9

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/hooks/useSearchConfig.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import warning from 'rc-util/lib/warning';
32
import * as React from 'react';
43
import type { CascaderProps, ShowSearchType } from '../Cascader';
@@ -22,8 +21,8 @@ export default function useSearchConfig(showSearch?: CascaderProps['showSearch']
2221
};
2322
}
2423

25-
if ((searchConfig.limit as number) <= 0) {
26-
searchConfig.limit = false;
24+
if ((searchConfig.limit as number) <= 0 && searchConfig.limit !== false) {
25+
delete searchConfig.limit;
2726

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

tests/search.limit.spec.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,36 @@ describe('Cascader.Search', () => {
4141
const itemList = wrapper.find('div.rc-cascader-menu-item-content');
4242
expect(itemList).toHaveLength(itemList.length);
4343
});
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(50);
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+
});
4476
});

0 commit comments

Comments
 (0)