Skip to content

Commit

Permalink
fix: onChange prop in PhoneInput component (#4)
Browse files Browse the repository at this point in the history
Updated default value in react-phone-number-input package from 'undefined' to 'null' for consistency with react-hook-form recommendation.
  • Loading branch information
omeralpi authored Feb 20, 2024
1 parent fb5285d commit 832f070
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion components/ui/phone-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@ type PhoneInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChan
const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> = React.forwardRef<
React.ElementRef<typeof RPNInput.default>,
PhoneInputProps
>(({ className, ...props }, ref) => (
>(({ className, onChange, ...props }, ref) => (
<RPNInput.default
ref={ref}
placeholder={"Enter a phone number"}
className={cn("flex", className)}
flagComponent={FlagComponent}
countrySelectComponent={CountrySelect}
inputComponent={InputComponent}
/**
* Handles the onChange event.
*
* react-phone-number-input might trigger the onChange event as undefined
* when a valid phone number is not entered. To prevent this,
* the value is coerced to an empty string.
*
* @param {E164Number | undefined} value - The entered value
*/
onChange={(value) => onChange(value || "")}
{...props}
/>
));
Expand Down

0 comments on commit 832f070

Please sign in to comment.