@input-kit/phone 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +240 -223
- package/dist/index.cjs +136 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +137 -48
- package/dist/index.js.map +1 -1
- package/package.json +91 -91
package/dist/index.cjs
CHANGED
|
@@ -2152,7 +2152,8 @@ var DEFAULT_PHONE_INPUT_LABELS = {
|
|
|
2152
2152
|
noCountriesFound: "No countries found",
|
|
2153
2153
|
searchCountriesAriaLabel: "Search countries",
|
|
2154
2154
|
countryOptionsAriaLabel: "Country options",
|
|
2155
|
-
countryButtonAriaLabel: "Open country selector"
|
|
2155
|
+
countryButtonAriaLabel: "Open country selector",
|
|
2156
|
+
countryResultsAnnouncement: "{count} countries"
|
|
2156
2157
|
};
|
|
2157
2158
|
var LABELS_BY_LANGUAGE = {
|
|
2158
2159
|
en: DEFAULT_PHONE_INPUT_LABELS,
|
|
@@ -2162,7 +2163,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2162
2163
|
noCountriesFound: "Aucun pays trouv\xE9",
|
|
2163
2164
|
searchCountriesAriaLabel: "Rechercher des pays",
|
|
2164
2165
|
countryOptionsAriaLabel: "Options de pays",
|
|
2165
|
-
countryButtonAriaLabel: "Ouvrir le s\xE9lecteur de pays"
|
|
2166
|
+
countryButtonAriaLabel: "Ouvrir le s\xE9lecteur de pays",
|
|
2167
|
+
countryResultsAnnouncement: "{count} pays"
|
|
2166
2168
|
},
|
|
2167
2169
|
de: {
|
|
2168
2170
|
selectCountry: "Land ausw\xE4hlen",
|
|
@@ -2170,7 +2172,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2170
2172
|
noCountriesFound: "Keine L\xE4nder gefunden",
|
|
2171
2173
|
searchCountriesAriaLabel: "L\xE4nder suchen",
|
|
2172
2174
|
countryOptionsAriaLabel: "L\xE4nderoptionen",
|
|
2173
|
-
countryButtonAriaLabel: "L\xE4nderauswahl \xF6ffnen"
|
|
2175
|
+
countryButtonAriaLabel: "L\xE4nderauswahl \xF6ffnen",
|
|
2176
|
+
countryResultsAnnouncement: "{count} L\xE4nder"
|
|
2174
2177
|
},
|
|
2175
2178
|
es: {
|
|
2176
2179
|
selectCountry: "Seleccionar pa\xEDs",
|
|
@@ -2178,7 +2181,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2178
2181
|
noCountriesFound: "No se encontraron pa\xEDses",
|
|
2179
2182
|
searchCountriesAriaLabel: "Buscar pa\xEDses",
|
|
2180
2183
|
countryOptionsAriaLabel: "Opciones de pa\xEDs",
|
|
2181
|
-
countryButtonAriaLabel: "Abrir selector de pa\xEDs"
|
|
2184
|
+
countryButtonAriaLabel: "Abrir selector de pa\xEDs",
|
|
2185
|
+
countryResultsAnnouncement: "{count} pa\xEDses"
|
|
2182
2186
|
},
|
|
2183
2187
|
pt: {
|
|
2184
2188
|
selectCountry: "Selecionar pa\xEDs",
|
|
@@ -2186,7 +2190,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2186
2190
|
noCountriesFound: "Nenhum pa\xEDs encontrado",
|
|
2187
2191
|
searchCountriesAriaLabel: "Pesquisar pa\xEDses",
|
|
2188
2192
|
countryOptionsAriaLabel: "Op\xE7\xF5es de pa\xEDs",
|
|
2189
|
-
countryButtonAriaLabel: "Abrir seletor de pa\xEDs"
|
|
2193
|
+
countryButtonAriaLabel: "Abrir seletor de pa\xEDs",
|
|
2194
|
+
countryResultsAnnouncement: "{count} pa\xEDses"
|
|
2190
2195
|
},
|
|
2191
2196
|
it: {
|
|
2192
2197
|
selectCountry: "Seleziona paese",
|
|
@@ -2194,7 +2199,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2194
2199
|
noCountriesFound: "Nessun paese trovato",
|
|
2195
2200
|
searchCountriesAriaLabel: "Cerca paesi",
|
|
2196
2201
|
countryOptionsAriaLabel: "Opzioni paese",
|
|
2197
|
-
countryButtonAriaLabel: "Apri selettore paese"
|
|
2202
|
+
countryButtonAriaLabel: "Apri selettore paese",
|
|
2203
|
+
countryResultsAnnouncement: "{count} paesi"
|
|
2198
2204
|
},
|
|
2199
2205
|
ja: {
|
|
2200
2206
|
selectCountry: "\u56FD\u3092\u9078\u629E",
|
|
@@ -2202,7 +2208,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2202
2208
|
noCountriesFound: "\u56FD\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093",
|
|
2203
2209
|
searchCountriesAriaLabel: "\u56FD\u3092\u691C\u7D22",
|
|
2204
2210
|
countryOptionsAriaLabel: "\u56FD\u306E\u5019\u88DC",
|
|
2205
|
-
countryButtonAriaLabel: "\u56FD\u306E\u30BB\u30EC\u30AF\u30BF\u30FC\u3092\u958B\u304F"
|
|
2211
|
+
countryButtonAriaLabel: "\u56FD\u306E\u30BB\u30EC\u30AF\u30BF\u30FC\u3092\u958B\u304F",
|
|
2212
|
+
countryResultsAnnouncement: "{count} \u4EF6\u306E\u56FD"
|
|
2206
2213
|
},
|
|
2207
2214
|
ko: {
|
|
2208
2215
|
selectCountry: "\uAD6D\uAC00 \uC120\uD0DD",
|
|
@@ -2210,7 +2217,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2210
2217
|
noCountriesFound: "\uAD6D\uAC00\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4",
|
|
2211
2218
|
searchCountriesAriaLabel: "\uAD6D\uAC00 \uAC80\uC0C9",
|
|
2212
2219
|
countryOptionsAriaLabel: "\uAD6D\uAC00 \uC635\uC158",
|
|
2213
|
-
countryButtonAriaLabel: "\uAD6D\uAC00 \uC120\uD0DD\uAE30 \uC5F4\uAE30"
|
|
2220
|
+
countryButtonAriaLabel: "\uAD6D\uAC00 \uC120\uD0DD\uAE30 \uC5F4\uAE30",
|
|
2221
|
+
countryResultsAnnouncement: "\uAD6D\uAC00 {count}\uAC1C"
|
|
2214
2222
|
},
|
|
2215
2223
|
zh: {
|
|
2216
2224
|
selectCountry: "\u9009\u62E9\u56FD\u5BB6",
|
|
@@ -2218,7 +2226,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2218
2226
|
noCountriesFound: "\u672A\u627E\u5230\u56FD\u5BB6",
|
|
2219
2227
|
searchCountriesAriaLabel: "\u641C\u7D22\u56FD\u5BB6",
|
|
2220
2228
|
countryOptionsAriaLabel: "\u56FD\u5BB6\u9009\u9879",
|
|
2221
|
-
countryButtonAriaLabel: "\u6253\u5F00\u56FD\u5BB6\u9009\u62E9\u5668"
|
|
2229
|
+
countryButtonAriaLabel: "\u6253\u5F00\u56FD\u5BB6\u9009\u62E9\u5668",
|
|
2230
|
+
countryResultsAnnouncement: "{count} \u4E2A\u56FD\u5BB6"
|
|
2222
2231
|
},
|
|
2223
2232
|
ar: {
|
|
2224
2233
|
selectCountry: "\u0627\u062E\u062A\u0631 \u0627\u0644\u062F\u0648\u0644\u0629",
|
|
@@ -2226,7 +2235,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2226
2235
|
noCountriesFound: "\u0644\u0645 \u064A\u062A\u0645 \u0627\u0644\u0639\u062B\u0648\u0631 \u0639\u0644\u0649 \u062F\u0648\u0644",
|
|
2227
2236
|
searchCountriesAriaLabel: "\u0627\u0628\u062D\u062B \u0639\u0646 \u0627\u0644\u062F\u0648\u0644",
|
|
2228
2237
|
countryOptionsAriaLabel: "\u062E\u064A\u0627\u0631\u0627\u062A \u0627\u0644\u062F\u0648\u0644",
|
|
2229
|
-
countryButtonAriaLabel: "\u0627\u0641\u062A\u062D \u0645\u062D\u062F\u062F \u0627\u0644\u062F\u0648\u0644\u0629"
|
|
2238
|
+
countryButtonAriaLabel: "\u0627\u0641\u062A\u062D \u0645\u062D\u062F\u062F \u0627\u0644\u062F\u0648\u0644\u0629",
|
|
2239
|
+
countryResultsAnnouncement: "{count} \u062F\u0648\u0644\u0629"
|
|
2230
2240
|
},
|
|
2231
2241
|
hi: {
|
|
2232
2242
|
selectCountry: "\u0926\u0947\u0936 \u091A\u0941\u0928\u0947\u0902",
|
|
@@ -2234,7 +2244,8 @@ var LABELS_BY_LANGUAGE = {
|
|
|
2234
2244
|
noCountriesFound: "\u0915\u094B\u0908 \u0926\u0947\u0936 \u0928\u0939\u0940\u0902 \u092E\u093F\u0932\u093E",
|
|
2235
2245
|
searchCountriesAriaLabel: "\u0926\u0947\u0936 \u0916\u094B\u091C\u0947\u0902",
|
|
2236
2246
|
countryOptionsAriaLabel: "\u0926\u0947\u0936 \u0935\u093F\u0915\u0932\u094D\u092A",
|
|
2237
|
-
countryButtonAriaLabel: "\u0926\u0947\u0936 \u091A\u092F\u0928 \u0916\u094B\u0932\u0947\u0902"
|
|
2247
|
+
countryButtonAriaLabel: "\u0926\u0947\u0936 \u091A\u092F\u0928 \u0916\u094B\u0932\u0947\u0902",
|
|
2248
|
+
countryResultsAnnouncement: "{count} \u0926\u0947\u0936"
|
|
2238
2249
|
}
|
|
2239
2250
|
};
|
|
2240
2251
|
function getPrimaryLanguage(locale) {
|
|
@@ -2576,6 +2587,8 @@ function usePhoneInput(options = {}) {
|
|
|
2576
2587
|
const [country, setCountry] = react.useState(initialCountry);
|
|
2577
2588
|
const [isOpen, setIsOpen] = react.useState(false);
|
|
2578
2589
|
const [searchQuery, setSearchQuery] = react.useState("");
|
|
2590
|
+
const [highlightedIndex, setHighlightedIndex] = react.useState(0);
|
|
2591
|
+
const listboxId = react.useId();
|
|
2579
2592
|
const phone = isControlled ? controlledValue : internalPhone;
|
|
2580
2593
|
const getOutputCountry = react.useCallback(
|
|
2581
2594
|
(nextCountry) => localizeCountry(nextCountry, locale),
|
|
@@ -2646,6 +2659,26 @@ function usePhoneInput(options = {}) {
|
|
|
2646
2659
|
() => filterCountries(localizedCountries, searchQuery, preferredCountries),
|
|
2647
2660
|
[localizedCountries, searchQuery, preferredCountries]
|
|
2648
2661
|
);
|
|
2662
|
+
react.useEffect(() => {
|
|
2663
|
+
setHighlightedIndex(0);
|
|
2664
|
+
}, [searchQuery]);
|
|
2665
|
+
react.useEffect(() => {
|
|
2666
|
+
setHighlightedIndex((current) => {
|
|
2667
|
+
if (filteredCountries.length === 0) {
|
|
2668
|
+
return 0;
|
|
2669
|
+
}
|
|
2670
|
+
return current >= filteredCountries.length ? filteredCountries.length - 1 : current;
|
|
2671
|
+
});
|
|
2672
|
+
}, [filteredCountries.length]);
|
|
2673
|
+
const wasOpenRef = react.useRef(false);
|
|
2674
|
+
react.useEffect(() => {
|
|
2675
|
+
if (isOpen && !wasOpenRef.current) {
|
|
2676
|
+
const selectedIndex = filteredCountries.findIndex((candidate) => candidate.code === country?.code);
|
|
2677
|
+
setHighlightedIndex(selectedIndex >= 0 ? selectedIndex : 0);
|
|
2678
|
+
}
|
|
2679
|
+
wasOpenRef.current = isOpen;
|
|
2680
|
+
}, [isOpen, filteredCountries, country?.code]);
|
|
2681
|
+
const activeCountry = filteredCountries[highlightedIndex];
|
|
2649
2682
|
useIsomorphicLayoutEffect(() => {
|
|
2650
2683
|
const nextDigitIndex = pendingCaretDigitIndexRef.current;
|
|
2651
2684
|
const input = inputRef.current;
|
|
@@ -2758,11 +2791,22 @@ function usePhoneInput(options = {}) {
|
|
|
2758
2791
|
(code) => `phone-input-country-${code}`,
|
|
2759
2792
|
[]
|
|
2760
2793
|
);
|
|
2794
|
+
const activeOptionId = activeCountry ? getCountryOptionId(activeCountry.code) : void 0;
|
|
2795
|
+
const countryResultsText = filteredCountries.length === 0 ? resolvedLabels.noCountriesFound : resolvedLabels.countryResultsAnnouncement.replace("{count}", String(filteredCountries.length));
|
|
2796
|
+
const moveHighlight = react.useCallback(
|
|
2797
|
+
(nextIndex) => {
|
|
2798
|
+
const lastIndex = filteredCountries.length - 1;
|
|
2799
|
+
setHighlightedIndex(lastIndex < 0 ? 0 : Math.min(Math.max(nextIndex, 0), lastIndex));
|
|
2800
|
+
},
|
|
2801
|
+
[filteredCountries.length]
|
|
2802
|
+
);
|
|
2761
2803
|
const getCountryOptionProps = react.useCallback(
|
|
2762
2804
|
(optionCountry, index) => ({
|
|
2763
2805
|
id: getCountryOptionId(optionCountry.code),
|
|
2764
2806
|
role: "option",
|
|
2765
|
-
|
|
2807
|
+
// Selection follows the active option in a single-select listbox, so this
|
|
2808
|
+
// tracks the highlight rather than the committed country.
|
|
2809
|
+
"aria-selected": index === highlightedIndex,
|
|
2766
2810
|
onClick: () => selectCountry(optionCountry),
|
|
2767
2811
|
onKeyDown: (event) => {
|
|
2768
2812
|
if (event.key === "Enter" || event.key === " ") {
|
|
@@ -2776,7 +2820,7 @@ function usePhoneInput(options = {}) {
|
|
|
2776
2820
|
},
|
|
2777
2821
|
tabIndex: index === 0 ? 0 : -1
|
|
2778
2822
|
}),
|
|
2779
|
-
[closeDropdown,
|
|
2823
|
+
[closeDropdown, highlightedIndex, getCountryOptionId, selectCountry]
|
|
2780
2824
|
);
|
|
2781
2825
|
return {
|
|
2782
2826
|
// State
|
|
@@ -2791,6 +2835,9 @@ function usePhoneInput(options = {}) {
|
|
|
2791
2835
|
searchQuery,
|
|
2792
2836
|
labels: resolvedLabels,
|
|
2793
2837
|
formattedValue: formattedPhone,
|
|
2838
|
+
highlightedIndex,
|
|
2839
|
+
activeCountry,
|
|
2840
|
+
countryResultsText,
|
|
2794
2841
|
// Actions
|
|
2795
2842
|
setPhone,
|
|
2796
2843
|
setValue: setPhone,
|
|
@@ -2802,6 +2849,8 @@ function usePhoneInput(options = {}) {
|
|
|
2802
2849
|
closeDropdown,
|
|
2803
2850
|
close: closeDropdown,
|
|
2804
2851
|
setSearchQuery,
|
|
2852
|
+
setHighlightedIndex,
|
|
2853
|
+
moveHighlight,
|
|
2805
2854
|
clear,
|
|
2806
2855
|
// Props
|
|
2807
2856
|
inputProps: {
|
|
@@ -2820,7 +2869,21 @@ function usePhoneInput(options = {}) {
|
|
|
2820
2869
|
onClick: toggleDropdown,
|
|
2821
2870
|
"aria-expanded": isOpen,
|
|
2822
2871
|
"aria-haspopup": "listbox",
|
|
2823
|
-
"aria-label": countryButtonAriaLabel
|
|
2872
|
+
"aria-label": countryButtonAriaLabel,
|
|
2873
|
+
"aria-controls": listboxId
|
|
2874
|
+
},
|
|
2875
|
+
// The search field is the combobox: it keeps focus while the arrow keys
|
|
2876
|
+
// move `aria-activedescendant` through the listbox.
|
|
2877
|
+
countrySearchProps: {
|
|
2878
|
+
role: "combobox",
|
|
2879
|
+
value: searchQuery,
|
|
2880
|
+
onChange: (event) => setSearchQuery(event.target.value),
|
|
2881
|
+
"aria-expanded": isOpen,
|
|
2882
|
+
"aria-controls": listboxId,
|
|
2883
|
+
"aria-autocomplete": "list",
|
|
2884
|
+
"aria-activedescendant": activeOptionId,
|
|
2885
|
+
"aria-label": resolvedLabels.searchCountriesAriaLabel,
|
|
2886
|
+
placeholder: resolvedLabels.countrySearchPlaceholder
|
|
2824
2887
|
},
|
|
2825
2888
|
countrySelectorProps: {
|
|
2826
2889
|
onClick: toggleDropdown,
|
|
@@ -2829,9 +2892,12 @@ function usePhoneInput(options = {}) {
|
|
|
2829
2892
|
"aria-label": countryButtonAriaLabel
|
|
2830
2893
|
},
|
|
2831
2894
|
dropdownProps: {
|
|
2895
|
+
id: listboxId,
|
|
2832
2896
|
role: "listbox",
|
|
2833
2897
|
"aria-label": resolvedLabels.countryOptionsAriaLabel
|
|
2834
2898
|
},
|
|
2899
|
+
listboxId,
|
|
2900
|
+
activeOptionId,
|
|
2835
2901
|
getCountryOptionId,
|
|
2836
2902
|
filteredCountries,
|
|
2837
2903
|
countries: filteredCountries,
|
|
@@ -2866,24 +2932,25 @@ var PhoneInput = react.forwardRef(
|
|
|
2866
2932
|
const inputRef = react.useRef(null);
|
|
2867
2933
|
const optionRefs = react.useRef([]);
|
|
2868
2934
|
const countryButtonRef = react.useRef(null);
|
|
2869
|
-
const [highlightedIndex, setHighlightedIndex] = react.useState(0);
|
|
2870
|
-
const listboxId = react.useId();
|
|
2871
2935
|
const {
|
|
2872
2936
|
inputProps,
|
|
2873
2937
|
countryButtonProps,
|
|
2938
|
+
countrySearchProps,
|
|
2874
2939
|
dropdownProps,
|
|
2875
2940
|
country,
|
|
2876
2941
|
filteredCountries,
|
|
2877
2942
|
isOpen,
|
|
2878
2943
|
isValid,
|
|
2879
|
-
searchQuery,
|
|
2880
|
-
setSearchQuery,
|
|
2881
2944
|
setCountry,
|
|
2882
2945
|
selectCountry,
|
|
2883
2946
|
clear,
|
|
2884
2947
|
openDropdown,
|
|
2885
2948
|
closeDropdown,
|
|
2886
2949
|
getCountryOptionId,
|
|
2950
|
+
highlightedIndex,
|
|
2951
|
+
setHighlightedIndex,
|
|
2952
|
+
moveHighlight,
|
|
2953
|
+
countryResultsText,
|
|
2887
2954
|
labels
|
|
2888
2955
|
} = usePhoneInput({
|
|
2889
2956
|
value,
|
|
@@ -2913,7 +2980,6 @@ var PhoneInput = react.forwardRef(
|
|
|
2913
2980
|
}, []);
|
|
2914
2981
|
const handleCountryClick = react.useCallback((c) => {
|
|
2915
2982
|
selectCountry(c);
|
|
2916
|
-
setHighlightedIndex(0);
|
|
2917
2983
|
returnFocusToButton();
|
|
2918
2984
|
}, [selectCountry, returnFocusToButton]);
|
|
2919
2985
|
const handleCountryKeyDown = react.useCallback((e, c, index) => {
|
|
@@ -2922,7 +2988,6 @@ var PhoneInput = react.forwardRef(
|
|
|
2922
2988
|
case " ":
|
|
2923
2989
|
e.preventDefault();
|
|
2924
2990
|
selectCountry(c);
|
|
2925
|
-
setHighlightedIndex(0);
|
|
2926
2991
|
returnFocusToButton();
|
|
2927
2992
|
break;
|
|
2928
2993
|
case "ArrowDown":
|
|
@@ -2959,7 +3024,7 @@ var PhoneInput = react.forwardRef(
|
|
|
2959
3024
|
returnFocusToButton();
|
|
2960
3025
|
break;
|
|
2961
3026
|
}
|
|
2962
|
-
}, [selectCountry, filteredCountries.length, closeDropdown, returnFocusToButton]);
|
|
3027
|
+
}, [selectCountry, filteredCountries.length, closeDropdown, returnFocusToButton, setHighlightedIndex]);
|
|
2963
3028
|
react.useEffect(() => {
|
|
2964
3029
|
if (!isOpen) {
|
|
2965
3030
|
return;
|
|
@@ -2984,16 +3049,14 @@ var PhoneInput = react.forwardRef(
|
|
|
2984
3049
|
};
|
|
2985
3050
|
}, [isOpen, closeDropdown]);
|
|
2986
3051
|
react.useEffect(() => {
|
|
2987
|
-
if (
|
|
2988
|
-
if (highlightedIndex !== 0) {
|
|
2989
|
-
setHighlightedIndex(0);
|
|
2990
|
-
}
|
|
3052
|
+
if (!isOpen || !searchable) {
|
|
2991
3053
|
return;
|
|
2992
3054
|
}
|
|
2993
|
-
|
|
2994
|
-
|
|
3055
|
+
const activeOption = optionRefs.current[highlightedIndex];
|
|
3056
|
+
if (typeof activeOption?.scrollIntoView === "function") {
|
|
3057
|
+
activeOption.scrollIntoView({ block: "nearest" });
|
|
2995
3058
|
}
|
|
2996
|
-
}, [
|
|
3059
|
+
}, [isOpen, searchable, highlightedIndex]);
|
|
2997
3060
|
react.useImperativeHandle(ref, () => ({
|
|
2998
3061
|
focus,
|
|
2999
3062
|
blur,
|
|
@@ -3004,16 +3067,39 @@ var PhoneInput = react.forwardRef(
|
|
|
3004
3067
|
close: closeDropdown
|
|
3005
3068
|
}));
|
|
3006
3069
|
const handleSearchKeyDown = react.useCallback((e) => {
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3070
|
+
switch (e.key) {
|
|
3071
|
+
case "ArrowDown":
|
|
3072
|
+
e.preventDefault();
|
|
3073
|
+
moveHighlight(highlightedIndex + 1);
|
|
3074
|
+
break;
|
|
3075
|
+
case "ArrowUp":
|
|
3076
|
+
e.preventDefault();
|
|
3077
|
+
moveHighlight(highlightedIndex - 1);
|
|
3078
|
+
break;
|
|
3079
|
+
case "Home":
|
|
3080
|
+
e.preventDefault();
|
|
3081
|
+
moveHighlight(0);
|
|
3082
|
+
break;
|
|
3083
|
+
case "End":
|
|
3084
|
+
e.preventDefault();
|
|
3085
|
+
moveHighlight(filteredCountries.length - 1);
|
|
3086
|
+
break;
|
|
3087
|
+
case "Enter": {
|
|
3088
|
+
const active = filteredCountries[highlightedIndex];
|
|
3089
|
+
if (active) {
|
|
3090
|
+
e.preventDefault();
|
|
3091
|
+
selectCountry(active);
|
|
3092
|
+
returnFocusToButton();
|
|
3093
|
+
}
|
|
3094
|
+
break;
|
|
3095
|
+
}
|
|
3096
|
+
case "Escape":
|
|
3097
|
+
e.preventDefault();
|
|
3098
|
+
closeDropdown();
|
|
3099
|
+
returnFocusToButton();
|
|
3100
|
+
break;
|
|
3015
3101
|
}
|
|
3016
|
-
}, [closeDropdown, returnFocusToButton]);
|
|
3102
|
+
}, [closeDropdown, returnFocusToButton, moveHighlight, highlightedIndex, filteredCountries, selectCountry]);
|
|
3017
3103
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: containerRef, className: containerClassName, "data-valid": isValid, children: [
|
|
3018
3104
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3019
3105
|
"button",
|
|
@@ -3024,7 +3110,6 @@ var PhoneInput = react.forwardRef(
|
|
|
3024
3110
|
className: selectorClassName,
|
|
3025
3111
|
disabled,
|
|
3026
3112
|
tabIndex: disabled ? -1 : 0,
|
|
3027
|
-
"aria-controls": listboxId,
|
|
3028
3113
|
children: [
|
|
3029
3114
|
country ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3030
3115
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "phone-input-flag", children: country.flag }),
|
|
@@ -3053,22 +3138,26 @@ var PhoneInput = react.forwardRef(
|
|
|
3053
3138
|
searchable && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "phone-input-search", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3054
3139
|
"input",
|
|
3055
3140
|
{
|
|
3141
|
+
...countrySearchProps,
|
|
3056
3142
|
type: "text",
|
|
3057
|
-
value: searchQuery,
|
|
3058
|
-
onChange: (e) => setSearchQuery(e.target.value),
|
|
3059
3143
|
onKeyDown: handleSearchKeyDown,
|
|
3060
|
-
|
|
3061
|
-
autoFocus: true,
|
|
3062
|
-
"aria-controls": listboxId,
|
|
3063
|
-
"aria-label": labels.searchCountriesAriaLabel
|
|
3144
|
+
autoFocus: true
|
|
3064
3145
|
}
|
|
3065
3146
|
) }),
|
|
3147
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
3148
|
+
"div",
|
|
3149
|
+
{
|
|
3150
|
+
role: "status",
|
|
3151
|
+
"aria-live": "polite",
|
|
3152
|
+
style: { position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap" },
|
|
3153
|
+
children: countryResultsText
|
|
3154
|
+
}
|
|
3155
|
+
),
|
|
3066
3156
|
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
3067
3157
|
"ul",
|
|
3068
3158
|
{
|
|
3069
3159
|
...dropdownProps,
|
|
3070
3160
|
className: "phone-input-country-list",
|
|
3071
|
-
id: listboxId,
|
|
3072
3161
|
children: [
|
|
3073
3162
|
filteredCountries.map((c, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
3074
3163
|
"li",
|
|
@@ -3078,12 +3167,12 @@ var PhoneInput = react.forwardRef(
|
|
|
3078
3167
|
optionRefs.current[index] = element;
|
|
3079
3168
|
},
|
|
3080
3169
|
role: "option",
|
|
3081
|
-
"aria-selected":
|
|
3170
|
+
"aria-selected": index === highlightedIndex,
|
|
3082
3171
|
className: `phone-input-country-option ${c.code === country?.code ? "selected" : ""} ${index === highlightedIndex ? "highlighted" : ""}`,
|
|
3083
3172
|
onClick: () => handleCountryClick(c),
|
|
3084
3173
|
onKeyDown: (e) => handleCountryKeyDown(e, c, index),
|
|
3085
3174
|
onMouseEnter: () => setHighlightedIndex(index),
|
|
3086
|
-
tabIndex: index === highlightedIndex ? 0 : -1,
|
|
3175
|
+
tabIndex: searchable ? -1 : index === highlightedIndex ? 0 : -1,
|
|
3087
3176
|
children: [
|
|
3088
3177
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "phone-input-flag", children: c.flag }),
|
|
3089
3178
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "phone-input-country-name", children: getCountryDisplayName(c) }),
|