1- import { Cascader , Flex } from 'antd' ;
1+ import { Cascader , Flex , version } from 'antd' ;
22import type { CascaderProps } from 'antd' ;
33import classnames from 'classnames' ;
44import { useEvent , useMergedState } from 'rc-util' ;
@@ -8,6 +8,10 @@ import { useXProviderContext } from '../x-provider';
88import useStyle from './style' ;
99import useActive from './useActive' ;
1010
11+ const antdVersionCells = version . split ( '.' ) . map ( Number ) ;
12+ const isNewAPI =
13+ antdVersionCells [ 0 ] > 5 || ( antdVersionCells [ 0 ] === 5 && antdVersionCells [ 1 ] >= 25 ) ;
14+
1115export type SuggestionItem = {
1216 label : React . ReactNode ;
1317 value : string ;
@@ -121,17 +125,26 @@ function Suggestion<T = any>(props: SuggestionProps<T>) {
121125 const childNode = children ?.( { onTrigger, onKeyDown } ) ;
122126
123127 // ============================ Render ============================
128+ const onInternalOpenChange = ( nextOpen : boolean ) => {
129+ if ( ! nextOpen ) {
130+ onClose ( ) ;
131+ }
132+ } ;
133+
134+ const compatibleProps : Partial < CascaderProps > = { } ;
135+ if ( isNewAPI ) {
136+ compatibleProps . onDropdownVisibleChange = onInternalOpenChange ;
137+ } else {
138+ compatibleProps . onOpenChange = onInternalOpenChange ;
139+ }
140+
124141 return wrapCSSVar (
125142 < Cascader
126143 options = { itemList }
127144 open = { mergedOpen }
128145 value = { activePath }
129146 placement = { isRTL ? 'topRight' : 'topLeft' }
130- onDropdownVisibleChange = { ( nextOpen ) => {
131- if ( ! nextOpen ) {
132- onClose ( ) ;
133- }
134- } }
147+ { ...compatibleProps }
135148 optionRender = { optionRender }
136149 rootClassName = { classnames ( rootClassName , prefixCls , hashId , cssVarCls , {
137150 [ `${ prefixCls } -block` ] : block ,
0 commit comments