Skip to content

Commit 780eb44

Browse files
committed
fix: negative limit should not limit
1 parent 4598963 commit 780eb44

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/hooks/useSearchConfig.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ export default function useSearchConfig(showSearch?: CascaderProps['showSearch']
2222
};
2323
}
2424

25-
if (process.env.NODE_ENV !== 'production' && searchConfig.limit <= 0) {
26-
warning(false, "'limit' of showSearch should be positive number or false.");
25+
if (searchConfig.limit <= 0) {
26+
delete searchConfig.limit;
27+
28+
if (process.env.NODE_ENV !== 'production') {
29+
warning(false, "'limit' of showSearch should be positive number or false.");
30+
}
2731
}
2832

2933
return [true, searchConfig];

tests/search.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,15 @@ describe('Cascader.Search', () => {
161161
resetWarned();
162162
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
163163

164-
mount(<Cascader showSearch={{ limit: 0 }} />);
164+
const wrapper = mount(<Cascader options={options} showSearch={{ limit: 0 }} />);
165165

166166
expect(errorSpy).toHaveBeenCalledWith(
167167
"Warning: 'limit' of showSearch should be positive number or false.",
168168
);
169169

170+
doSearch(wrapper, 'toy');
171+
expect(wrapper.find('div.rc-cascader-menu-item-content')).toHaveLength(2);
172+
170173
errorSpy.mockRestore();
171174
});
172175
});

0 commit comments

Comments
 (0)