Skip to content

Commit 3fb810f

Browse files
ArtyomVancyanPedro Mendes
andauthored
Replace deprecated Select props (GH-123)
Co-authored-by: Pedro Mendes <pedro.mendes@perchpeek.com>
2 parents 70746c9 + 1cac3ca commit 3fb810f

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.3.13",
2+
"version": "0.3.14",
33
"name": "antd-phone-input",
44
"description": "Advanced, highly customizable phone input component for Ant Design.",
55
"keywords": [

src/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import useFormInstance from "antd/es/form/hooks/useFormInstance";
1515
import {ConfigContext} from "antd/es/config-provider";
1616
import {FormContext} from "antd/es/form/context";
1717
import {useWatch} from "antd/es/form/Form";
18+
import version from "antd/es/version";
1819
import Select from "antd/es/select";
1920
import Input from "antd/es/input";
2021

@@ -36,6 +37,10 @@ import locale from "./locale";
3637
import {injectMergedStyles} from "./styles";
3738
import {PhoneInputProps, PhoneNumber} from "./types";
3839

40+
const [major, minor, _] = version.split(".").map(Number);
41+
const isV5x = major === 5;
42+
const isV5x25 = isV5x && minor >= 25;
43+
3944
const PhoneInput = forwardRef(({
4045
value: initialValue = "",
4146
country = getDefaultISO2Code(),
@@ -221,9 +226,9 @@ const PhoneInput = forwardRef(({
221226
inputRef.current.input.focus();
222227
}}
223228
optionLabelProp="label"
224-
dropdownStyle={{minWidth}}
225-
onDropdownVisibleChange={onDropdownVisibleChange}
226-
dropdownRender={(menu) => (
229+
{...(isV5x ? {onOpenChange: onDropdownVisibleChange} : {onDropdownVisibleChange})}
230+
{...(isV5x25 ? {styles: {popup: {root: {minWidth}}}} : {dropdownStyle: {minWidth}})}
231+
{...({[isV5x ? "popupRender" : "dropdownRender"]: (menu: any) => (
227232
<div className={`${prefixCls}-phone-input-search-wrapper`}>
228233
{enableSearch && (
229234
<Input
@@ -237,7 +242,7 @@ const PhoneInput = forwardRef(({
237242
<div className="ant-select-item-empty">{searchNotFound}</div>
238243
)}
239244
</div>
240-
)}
245+
)})}
241246
>
242247
<Select.Option
243248
children={null}

0 commit comments

Comments
 (0)