Skip to content

Commit 4598963

Browse files
committed
chore: Warning of searchConfig when limit is negative
1 parent 7d50058 commit 4598963

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/hooks/useSearchConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import warning from 'rc-util/lib/warning';
23
import type { ShowSearchType } from '../interface';
34
import type { CascaderProps } from '../Cascader';
45

@@ -21,6 +22,10 @@ export default function useSearchConfig(showSearch?: CascaderProps['showSearch']
2122
};
2223
}
2324

25+
if (process.env.NODE_ENV !== 'production' && searchConfig.limit <= 0) {
26+
warning(false, "'limit' of showSearch should be positive number or false.");
27+
}
28+
2429
return [true, searchConfig];
2530
}, [showSearch]);
2631
}

tests/search.spec.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import React from 'react';
44
import KeyCode from 'rc-util/lib/KeyCode';
5+
import { resetWarned } from 'rc-util/lib/warning';
56
import { mount, ReactWrapper } from './enzyme';
67
import Cascader from '../src';
78

@@ -155,4 +156,17 @@ describe('Cascader.Search', () => {
155156
doSearch(wrapper, 'not exist');
156157
expect(wrapper.exists('.rc-cascader-menu-empty')).toBeTruthy();
157158
});
159+
160+
it('warning of negative limit', () => {
161+
resetWarned();
162+
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
163+
164+
mount(<Cascader showSearch={{ limit: 0 }} />);
165+
166+
expect(errorSpy).toHaveBeenCalledWith(
167+
"Warning: 'limit' of showSearch should be positive number or false.",
168+
);
169+
170+
errorSpy.mockRestore();
171+
});
158172
});

0 commit comments

Comments
 (0)