Skip to content

Commit

Permalink
fix: Refactor PhoneInputNumberInput component to handle phone number …
Browse files Browse the repository at this point in the history
…formatting and synchronization with input element
  • Loading branch information
iPagar committed Apr 16, 2024
1 parent d2f7091 commit 3475f89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/phone-input/phone-input-number-input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import clsx from 'clsx';
import React, { forwardRef, useEffect, useRef } from 'react';

import { formatPhoneNumber } from '../lib';
import styles from './phone-input.module.scss';
import { usePhoneInput } from './phone-input-provider';

Expand Down Expand Up @@ -80,7 +81,11 @@ export const PhoneInputNumberInput = forwardRef<
formatting.current = false;
}}
ref={inputRef}
value={props.value}
value={
typeof props.value === 'string'
? formatPhoneNumber(props.value)
: props.value
}
/>
);
});
Expand Down
1 change: 0 additions & 1 deletion stories/phone-input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export function ReactHookFormAndZod() {
handleSubmit,
register,
reset,
watch,
} = useForm<z.infer<typeof schema>>({
defaultValues,
resolver: zodResolver(schema),
Expand Down

0 comments on commit 3475f89

Please sign in to comment.