Skip to content

Commit f06c3c0

Browse files
committed
fix: update phone input component to include value prop and refactor onSelect handler
1 parent cbdb4ef commit f06c3c0

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

components/ui/phone-input.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type PhoneInputProps = Omit<
3131

3232
const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =
3333
React.forwardRef<React.ElementRef<typeof RPNInput.default>, PhoneInputProps>(
34-
({ className, onChange, ...props }, ref) => {
34+
({ className, onChange, value, ...props }, ref) => {
3535
return (
3636
<RPNInput.default
3737
ref={ref}
@@ -40,6 +40,7 @@ const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =
4040
countrySelectComponent={CountrySelect}
4141
inputComponent={InputComponent}
4242
smartCaret={false}
43+
value={value || undefined}
4344
/**
4445
* Handles the onChange event.
4546
*
@@ -166,14 +167,13 @@ const CountrySelectOption = ({
166167
onChange,
167168
onSelectComplete,
168169
}: CountrySelectOptionProps) => {
170+
const handleSelect = () => {
171+
onChange(country);
172+
onSelectComplete();
173+
};
174+
169175
return (
170-
<CommandItem
171-
className="gap-2"
172-
onSelect={() => {
173-
onChange(country);
174-
onSelectComplete();
175-
}}
176-
>
176+
<CommandItem className="gap-2" onSelect={handleSelect}>
177177
<FlagComponent country={country} countryName={countryName} />
178178
<span className="flex-1 text-sm">{countryName}</span>
179179
<span className="text-sm text-foreground/50">{`+${RPNInput.getCountryCallingCode(country)}`}</span>

content/snippets/phone-input.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type PhoneInputProps = Omit<
3737

3838
const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =
3939
React.forwardRef<React.ElementRef<typeof RPNInput.default>, PhoneInputProps>(
40-
({ className, onChange, ...props }, ref) => {
40+
({ className, onChange, value, ...props }, ref) => {
4141
return (
4242
<RPNInput.default
4343
ref={ref}
@@ -46,6 +46,7 @@ const PhoneInput: React.ForwardRefExoticComponent<PhoneInputProps> =
4646
countrySelectComponent={CountrySelect}
4747
inputComponent={InputComponent}
4848
smartCaret={false}
49+
value={value || undefined}
4950
/**
5051
* Handles the onChange event.
5152
*
@@ -172,14 +173,13 @@ const CountrySelectOption = ({
172173
onChange,
173174
onSelectComplete,
174175
}: CountrySelectOptionProps) => {
176+
const handleSelect = () => {
177+
onChange(country);
178+
onSelectComplete();
179+
};
180+
175181
return (
176-
<CommandItem
177-
className="gap-2"
178-
onSelect={() => {
179-
onChange(country);
180-
onSelectComplete();
181-
}}
182-
>
182+
<CommandItem className="gap-2" onSelect={handleSelect}>
183183
<FlagComponent country={country} countryName={countryName} />
184184
<span className="flex-1 text-sm">{countryName}</span>
185185
<span className="text-sm text-foreground/50">{`+${RPNInput.getCountryCallingCode(country)}`}</span>

0 commit comments

Comments
 (0)