File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react' ;
2+ import warning from 'rc-util/lib/warning' ;
23import type { ShowSearchType } from '../interface' ;
34import 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}
Original file line number Diff line number Diff line change 22
33import React from 'react' ;
44import KeyCode from 'rc-util/lib/KeyCode' ;
5+ import { resetWarned } from 'rc-util/lib/warning' ;
56import { mount , ReactWrapper } from './enzyme' ;
67import 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} ) ;
You can’t perform that action at this time.
0 commit comments