mirror of
https://github.com/baptisteArno/typebot.io.git
synced 2026-06-19 21:04:33 +08:00
🐛 Avoid country code reset on phone input emptying (#2000)
Fixed #1999 Prevent selected country code from resetting to INT when input is cleared - Removed the block that reset **selectedCountryCode** to **INT** when the input field was cleared. - This ensures that if a country is selected, clearing the input does not revert it to **INT**. --------- Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
This commit is contained in:
parent
9738b4d2c0
commit
f20a2ed9c3
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/js",
|
||||
"version": "0.3.47",
|
||||
"version": "0.3.48",
|
||||
"description": "Javascript library to display typebots on your website",
|
||||
"license": "FSL-1.1-ALv2",
|
||||
"type": "module",
|
||||
|
||||
@ -27,33 +27,27 @@ export const PhoneInput = (props: PhoneInputProps) => {
|
||||
|
||||
const handleInput = (inputValue: string | undefined) => {
|
||||
setInputValue(inputValue as string);
|
||||
if (
|
||||
(inputValue === "" || inputValue === "+") &&
|
||||
selectedCountryCode() !== "INT"
|
||||
)
|
||||
setSelectedCountryCode("INT");
|
||||
const matchedCountry =
|
||||
inputValue?.startsWith("+") &&
|
||||
inputValue.length > 2 &&
|
||||
phoneCountries.reduce<(typeof phoneCountries)[number] | null>(
|
||||
(matchedCountry, country) => {
|
||||
if (
|
||||
!country?.dial_code ||
|
||||
(matchedCountry !== null && !matchedCountry.dial_code)
|
||||
) {
|
||||
return matchedCountry;
|
||||
}
|
||||
if (
|
||||
inputValue?.startsWith(country.dial_code) &&
|
||||
country.dial_code.length > (matchedCountry?.dial_code.length ?? 0)
|
||||
) {
|
||||
return country;
|
||||
}
|
||||
|
||||
if (inputValue?.startsWith("+") && inputValue.length > 2) {
|
||||
const matchedCountry = phoneCountries.reduce<
|
||||
(typeof phoneCountries)[number] | null
|
||||
>((matchedCountry, country) => {
|
||||
if (
|
||||
!country?.dial_code ||
|
||||
(matchedCountry !== null && !matchedCountry.dial_code)
|
||||
) {
|
||||
return matchedCountry;
|
||||
},
|
||||
null,
|
||||
);
|
||||
if (matchedCountry) setSelectedCountryCode(matchedCountry.code);
|
||||
}
|
||||
if (
|
||||
inputValue?.startsWith(country.dial_code) &&
|
||||
country.dial_code.length > (matchedCountry?.dial_code.length ?? 0)
|
||||
) {
|
||||
return country;
|
||||
}
|
||||
return matchedCountry;
|
||||
}, null);
|
||||
if (matchedCountry) setSelectedCountryCode(matchedCountry.code);
|
||||
}
|
||||
};
|
||||
|
||||
const checkIfInputIsValid = () =>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/nextjs",
|
||||
"version": "0.3.47",
|
||||
"version": "0.3.48",
|
||||
"license": "FSL-1.1-ALv2",
|
||||
"description": "Convenient library to display typebots on your Next.js website",
|
||||
"type": "module",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@typebot.io/react",
|
||||
"version": "0.3.47",
|
||||
"version": "0.3.48",
|
||||
"description": "Convenient library to display typebots on your React app",
|
||||
"license": "FSL-1.1-ALv2",
|
||||
"type": "module",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user