|
|
@@ -85,11 +85,41 @@ export const PhoneNumberInput = React.forwardRef< |
|
|
|
const defaultRef = React.useRef<PhoneNumberInputDerivedElement>(null); |
|
|
|
const ref = forwardedRef ?? defaultRef; |
|
|
|
|
|
|
|
React.useEffect(() => { |
|
|
|
const { current: currentRaw } = defaultRef; |
|
|
|
const current = currentRaw as unknown as PhoneNumberInputDerivedElement; |
|
|
|
const forwardedRefProxy = new Proxy(current, { |
|
|
|
get(target, prop, receiver) { |
|
|
|
return Reflect.get(target, prop, receiver) as unknown; |
|
|
|
}, |
|
|
|
set(target, prop, newValue, receiver) { |
|
|
|
if (prop === 'value') { |
|
|
|
setPhoneNumber(newValue as string); |
|
|
|
current.value = newValue as string; |
|
|
|
return true; |
|
|
|
} |
|
|
|
return Reflect.set(target, prop, newValue, receiver); |
|
|
|
}, |
|
|
|
}) as unknown as PhoneNumberInputDerivedElement; |
|
|
|
|
|
|
|
if (typeof forwardedRef === 'function') { |
|
|
|
forwardedRef(forwardedRefProxy); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof forwardedRef === 'object' && forwardedRef) { |
|
|
|
const mutableForwardedRef = forwardedRef as React.MutableRefObject< |
|
|
|
PhoneNumberInputDerivedElement |
|
|
|
>; |
|
|
|
mutableForwardedRef.current = forwardedRefProxy; |
|
|
|
} |
|
|
|
}, [forwardedRef, defaultRef]); |
|
|
|
|
|
|
|
const handlePhoneInputChange = (phoneNumberValue: Value) => { |
|
|
|
if (!(typeof ref === 'object' && ref)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
const { current: input } = ref; |
|
|
|
const { current: input } = defaultRef; |
|
|
|
if (!input) { |
|
|
|
return; |
|
|
|
} |
|
|
@@ -156,7 +186,7 @@ export const PhoneNumberInput = React.forwardRef< |
|
|
|
size={length} |
|
|
|
value={value} |
|
|
|
onChange={onChange} |
|
|
|
ref={ref} |
|
|
|
ref={defaultRef} |
|
|
|
aria-labelledby={labelId} |
|
|
|
type="tel" |
|
|
|
id={id} |
|
|
|