Skip to content

Commit cefecc4

Browse files
Add support for Antd Design v6.x (GH-104)
2 parents 008c9e1 + 345b1f7 commit cefecc4

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

development/src/ant-phone/index.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {FormContext} from "antd/es/form/context";
1717
import {useWatch} from "antd/es/form/Form";
1818
import version from "antd/es/version";
1919
import Select from "antd/es/select";
20+
import Space from "antd/es/space";
2021
import Input from "antd/es/input";
2122

2223
import {
@@ -39,7 +40,8 @@ import {PhoneInputProps, PhoneNumber} from "./types";
3940

4041
const [major, minor, _] = version.split(".").map(Number);
4142
const isV5x = major === 5;
42-
const isV5x25 = isV5x && minor >= 25;
43+
const isV6x = major === 6;
44+
const isLatest = isV6x || (isV5x && minor >= 25);
4345

4446
const PhoneInput = forwardRef(({
4547
value: initialValue = "",
@@ -227,9 +229,10 @@ const PhoneInput = forwardRef(({
227229
inputRef.current.input.focus();
228230
}}
229231
optionLabelProp="label"
230-
{...(isV5x ? {onOpenChange: onDropdownVisibleChange} : {onDropdownVisibleChange})}
231-
{...(isV5x25 ? {styles: {popup: {root: {minWidth}}}} : {dropdownStyle: {minWidth}})}
232-
{...({[isV5x ? "popupRender" : "dropdownRender"]: (menu: any) => (
232+
style={{width: 42 + (enableArrow ? 24 : 0)}}
233+
{...((isV5x || isV6x) ? {onOpenChange: onDropdownVisibleChange} : {onDropdownVisibleChange})}
234+
{...(isLatest ? {styles: {popup: {root: {minWidth}}}} : {dropdownStyle: {minWidth}})}
235+
{...({[(isV5x || isV6x) ? "popupRender" : "dropdownRender"]: (menu: any) => (
233236
<div className={`${prefixCls}-phone-input-search-wrapper`}>
234237
{enableSearch && (
235238
<Input
@@ -250,7 +253,7 @@ const PhoneInput = forwardRef(({
250253
value={selectValue}
251254
style={{display: "none"}}
252255
key={`${countryCode}_default`}
253-
label={<div style={{display: "flex"}}>
256+
label={<div style={{display: "flex", alignItems: "center"}}>
254257
<div className={`flag ${countryCode} ${useSVG ? "svg" : ""}`}/>
255258
{suffixIcon}
256259
</div>}
@@ -261,7 +264,7 @@ const PhoneInput = forwardRef(({
261264
<Select.Option
262265
value={iso + dial}
263266
key={`${iso}_${mask}`}
264-
label={<div style={{display: "flex"}}>
267+
label={<div style={{display: "flex", alignItems: "center"}}>
265268
<div className={`flag ${iso} ${useSVG ? "svg" : ""}`}/>
266269
{suffixIcon}
267270
</div>}
@@ -273,22 +276,24 @@ const PhoneInput = forwardRef(({
273276
)
274277
})}
275278
</Select>
276-
), [selectValue, suffixIcon, countryCode, query, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countries, countriesList, setFieldValue, setValue, prefixCls, enableSearch, searchPlaceholder, useSVG])
279+
), [selectValue, suffixIcon, countryCode, query, disabled, disableParentheses, disableDropdown, onDropdownVisibleChange, minWidth, searchNotFound, countries, countriesList, setFieldValue, setValue, prefixCls, enableSearch, enableArrow, searchPlaceholder, useSVG])
277280

278281
return (
279282
<div className={`${prefixCls}-phone-input-wrapper`}
280283
ref={node => setMinWidth(node?.offsetWidth || 0)}>
281-
<Input
282-
ref={ref}
283-
inputMode="tel"
284-
value={value}
285-
onInput={onInput}
286-
onChange={onChange}
287-
onKeyDown={onKeyDown}
288-
addonBefore={dropdownRender(countriesSelect)}
289-
disabled={disabled}
290-
{...antInputProps}
291-
/>
284+
<Space.Compact>
285+
{dropdownRender(countriesSelect)}
286+
<Input
287+
ref={ref}
288+
inputMode="tel"
289+
value={value}
290+
onInput={onInput}
291+
onChange={onChange}
292+
onKeyDown={onKeyDown}
293+
disabled={disabled}
294+
{...antInputProps}
295+
/>
296+
</Space.Compact>
292297
</div>
293298
)
294299
})

development/src/ant-phone/resources/stylesheet.json

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,24 @@
1111
".ant-phone-input-search-wrapper .ant-select-item-empty": {
1212
"margin": "0 6px 6px 6px"
1313
},
14+
".ant-phone-input-wrapper .ant-space-compact": {
15+
"width": "100%"
16+
},
1417
".ant-phone-input-wrapper .ant-select-selector": {
1518
"padding": "0 11px !important",
16-
"height": "unset !important",
17-
"border": "none !important"
19+
"height": "unset !important"
20+
},
21+
".ant-phone-input-wrapper .ant-select-content input": {
22+
"display": "none !important"
23+
},
24+
".ant-phone-input-wrapper .ant-select-content-value": {
25+
"overflow": "visible !important",
26+
"display": "flex !important"
1827
},
1928
".ant-phone-input-wrapper .ant-select-selection-item": {
20-
"padding": "0 !important"
29+
"padding": "0 !important",
30+
"align-items": "center",
31+
"display": "flex"
2132
},
2233
".ant-phone-input-wrapper .ant-input-group-addon *": {
2334
"display": "flex",

0 commit comments

Comments
 (0)