import clsx from 'clsx'; import type { ReactNode } from 'react'; import React, { forwardRef, useImperativeHandle, useRef } from 'react'; import i18n from '../RecipientsInput/i18n'; import { RemoveButton } from '../RemoveButton'; import styles from './styles.scss'; export interface PhoneNumberInputHandles { focus: () => void; blur: () => void; } export interface PhoneNumberInputProps { currentLocale: string; placeholder?: ReactNode; value: string; onChange?: (value: string) => void; onClear?: () => void; onFocus?: () => void; isFocused?: boolean; } export const PhoneNumberInput = forwardRef< PhoneNumberInputHandles, PhoneNumberInputProps >( ( { currentLocale, placeholder = i18n.getString('enterNameOrNumber', currentLocale), value, onChange, onClear, onFocus, isFocused, }, ref, ) => { const inputEl = useRef(null); useImperativeHandle(ref, () => ({ focus() { // Ensure focus is called in the next event cycle // This avoids any event handler in the same cycle messing up the focus setTimeout(() => { if (inputEl.current) { // @ts-expect-error TS(2339): Property 'focus' does not exist on type 'never'. inputEl.current.focus(); } }, 0); }, blur() { if (inputEl.current) { // @ts-expect-error TS(2339): Property 'blur' does not exist on type 'never'. inputEl.current.blur(); } }, })); return (