номер телефона сбрасывается при смене маски

This commit is contained in:
Nastya 2025-09-15 08:07:06 +03:00
parent 7312f0e941
commit 3bb940047c
2 changed files with 15 additions and 6 deletions

@ -24,13 +24,13 @@ type InputProps = {
const TextField = MuiTextField as unknown as FC<TextFieldProps>; const TextField = MuiTextField as unknown as FC<TextFieldProps>;
let first = true; let first = true;
function phoneChange(e: ChangeEvent<HTMLInputElement>, mask: string) { function phoneChange(newValue: string, mask: string) {
const masked = IMask.createMask({ const masked = IMask.createMask({
mask: "+7 (000) 000-00-00", mask: "+7 (000) 000-00-00",
// ...and other options // ...and other options
}); });
masked.value = e.target.value; masked.value = newValue;
const a = IMask.pipe(e.target.value, { const a = IMask.pipe(newValue, {
mask, mask,
}); });
return a || ""; return a || "";
@ -68,7 +68,7 @@ export const CustomInput = ({
// inputRef={isPhone ? ref : null} // inputRef={isPhone ? ref : null}
//@ts-ignore //@ts-ignore
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange={(e: ChangeEvent<HTMLInputElement>) =>
isPhone ? onChangePhone?.(phoneChange(e, mask)) : onChange?.(e) isPhone ? onChangePhone?.(phoneChange(e.target.value, mask)) : onChange?.(e)
} }
onBlur={onBlur} onBlur={onBlur}
type={isPhone ? "tel" : type} type={isPhone ? "tel" : type}
@ -106,7 +106,16 @@ export const CustomInput = ({
</InputAdornment> </InputAdornment>
), ),
endAdornment: ( endAdornment: (
<InputAdornment position="end">{isPhone && <CountrySelector setMask={setMask} />}</InputAdornment> <InputAdornment position="end">
{isPhone && (
<CountrySelector
setMask={(e) => {
onChangePhone?.(phoneChange("", mask));
setMask(e);
}}
/>
)}
</InputAdornment>
), ),
}} }}
/> />

@ -12,7 +12,7 @@ const isProduction = !(
); );
//туризм больше не в исключениях //туризм больше не в исключениях
if (!isProduction) domain = "https://hbpn.link"; if (!isProduction) domain = "https://s.hbpn.link";
// domain = "https://hbpn.link"; // domain = "https://hbpn.link";
export { domain, isProduction }; export { domain, isProduction };