fix: phone number input optimized
This commit is contained in:
@ -20,14 +20,13 @@ type AdditionalProps = {
|
||||
|
||||
type InputProps = Omit<
|
||||
PolymorphicComponentProps<typeof IMaskInput, InputBaseProps>,
|
||||
"onChange" | "defaultValue"
|
||||
"onChange" | "defaultValue" | "value"
|
||||
>;
|
||||
|
||||
export type Props = AdditionalProps & InputProps;
|
||||
|
||||
const PhoneInput = ({
|
||||
initialCountryCode = "RU",
|
||||
value: _value,
|
||||
onChange: _onChange,
|
||||
setPhoneMask: _setPhoneMask,
|
||||
...props
|
||||
@ -41,8 +40,6 @@ const PhoneInput = ({
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [dropdownWidth, setDropdownWidth] = useState<number>(300);
|
||||
|
||||
const lastNotifiedValue = useRef<string | null>(value ?? "");
|
||||
|
||||
const onChange = (numberWithoutCode: string) => {
|
||||
setValue(numberWithoutCode);
|
||||
_onChange(`+${country.callingCode} ${numberWithoutCode}`);
|
||||
@ -57,14 +54,6 @@ const PhoneInput = ({
|
||||
setPhoneMask(initialData.current.format, country);
|
||||
}, [initialData.current.format]);
|
||||
|
||||
useEffect(() => {
|
||||
const localValue = value.trim();
|
||||
if (localValue !== lastNotifiedValue.current) {
|
||||
lastNotifiedValue.current = localValue;
|
||||
onChange(localValue);
|
||||
}
|
||||
}, [country.code, value]);
|
||||
|
||||
const { readOnly, disabled } = props;
|
||||
const leftSectionWidth = 90;
|
||||
|
||||
@ -108,7 +97,7 @@ const PhoneInput = ({
|
||||
inputMode={"numeric"}
|
||||
mask={mask}
|
||||
value={value}
|
||||
onAccept={value => setValue(value)}
|
||||
onAccept={onChange}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user