Skip to content

Commit 0ec94bc

Browse files
committed
chore: fix warning of deprecated API
1 parent 116d833 commit 0ec94bc

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

components/suggestion/index.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cascader, Flex } from 'antd';
1+
import { Cascader, Flex, version } from 'antd';
22
import type { CascaderProps } from 'antd';
33
import classnames from 'classnames';
44
import { useEvent, useMergedState } from 'rc-util';
@@ -8,6 +8,10 @@ import { useXProviderContext } from '../x-provider';
88
import useStyle from './style';
99
import 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+
1115
export 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,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"@umijs/fabric": "^4.0.1",
159159
"adm-zip": "^0.5.16",
160160
"ali-oss": "^6.21.0",
161-
"antd": "^5.22.7",
161+
"antd": "^5.25.1",
162162
"antd-style": "^3.6.3",
163163
"antd-token-previewer": "^2.0.8",
164164
"axios": "^1.7.7",

0 commit comments

Comments
 (0)