@@ -73,12 +73,15 @@ export const PhoneNumberInput = React.forwardRef< | |||||
onChange, | onChange, | ||||
name, | name, | ||||
length, | length, | ||||
defaultValue, | |||||
...etcProps | ...etcProps | ||||
}: PhoneNumberInputProps, | }: PhoneNumberInputProps, | ||||
forwardedRef, | forwardedRef, | ||||
) => { | ) => { | ||||
const { clientSide } = useClientSide({ clientSide: enhanced }); | const { clientSide } = useClientSide({ clientSide: enhanced }); | ||||
const [phoneNumber, setPhoneNumber] = React.useState<Value>(value?.toString() ?? ''); | |||||
const [phoneNumber, setPhoneNumber] = React.useState<Value>( | |||||
value?.toString() ?? defaultValue?.toString() ?? '' | |||||
); | |||||
const labelId = React.useId(); | const labelId = React.useId(); | ||||
const defaultId = React.useId(); | const defaultId = React.useId(); | ||||
const id = idProp ?? defaultId; | const id = idProp ?? defaultId; | ||||
@@ -150,6 +153,7 @@ export const PhoneNumberInput = React.forwardRef< | |||||
value={value} | value={value} | ||||
onChange={onChange} | onChange={onChange} | ||||
ref={defaultRef} | ref={defaultRef} | ||||
defaultValue={defaultValue} | |||||
aria-labelledby={labelId} | aria-labelledby={labelId} | ||||
type="tel" | type="tel" | ||||
id={id} | id={id} | ||||
@@ -64,8 +64,11 @@ export const useProxyInput = < | |||||
if (!input) { | if (!input) { | ||||
return; | return; | ||||
} | } | ||||
valueSetterFn(transformChangeHandlerArgs(e)); | |||||
delegateTriggerEvent('change', input, e); | |||||
const transformedValue = transformChangeHandlerArgs(e); | |||||
valueSetterFn(transformedValue); | |||||
setTimeout(() => { | |||||
delegateTriggerEvent('change', input, transformedValue); | |||||
}); | |||||
}, [valueSetterFn, transformChangeHandlerArgs, defaultRef]); | }, [valueSetterFn, transformChangeHandlerArgs, defaultRef]); | ||||
return React.useMemo(() => ({ | return React.useMemo(() => ({ | ||||
@@ -21,12 +21,31 @@ const TemporalPage: NextPage = () => { | |||||
onChange={(e) => { console.log('change', e.currentTarget.name, e.currentTarget, e.currentTarget.value)}} | onChange={(e) => { console.log('change', e.currentTarget.name, e.currentTarget, e.currentTarget.value)}} | ||||
/> | /> | ||||
</Subsection> | </Subsection> | ||||
<Subsection title="Non-enhanced"> | |||||
<Formatted.PhoneNumberInput | |||||
label="Phone" | |||||
name="phone" | |||||
border | |||||
onFocus={(e) => { console.log('focus', e.currentTarget)}} | |||||
onBlur={(e) => { console.log('blur', e.currentTarget)}} | |||||
onChange={(e) => { console.log('change', e.currentTarget.name, e.currentTarget, e.currentTarget.value)}} | |||||
/> | |||||
</Subsection> | |||||
<Subsection title="With Default Value"> | |||||
<Formatted.PhoneNumberInput | |||||
label="Phone" | |||||
name="phone2" | |||||
enhanced | |||||
border | |||||
defaultValue="+639876543210" | |||||
/> | |||||
</Subsection> | |||||
<Subsection title="With Ref"> | <Subsection title="With Ref"> | ||||
<div className="flex gap-4 flex-wrap"> | <div className="flex gap-4 flex-wrap"> | ||||
<div> | <div> | ||||
<Formatted.PhoneNumberInput | <Formatted.PhoneNumberInput | ||||
label="Phone" | label="Phone" | ||||
name="phone" | |||||
name="phone3" | |||||
enhanced | enhanced | ||||
border | border | ||||
ref={phoneNumberRef} | ref={phoneNumberRef} | ||||