Skip to content

Commit

Permalink
add react support
Browse files Browse the repository at this point in the history
  • Loading branch information
bgb10 authored and jackocnr committed Jul 31, 2024
1 parent f065f46 commit d7db453
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions react/src/intl-tel-input/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ItiProps = {
usePreciseValidation?: boolean;
initOptions?: SomeOptions;
inputProps?: object;
disabled?: boolean | undefined;
};

export type IntlTelInputRef = {
Expand All @@ -31,6 +32,7 @@ const IntlTelInput = forwardRef(function IntlTelInput({
usePreciseValidation = false,
initOptions = {},
inputProps = {},
disabled = undefined,
}: ItiProps, ref: React.ForwardedRef<IntlTelInputRef>) {
const inputRef = useRef<HTMLInputElement | null>(null);
const itiRef = useRef<Iti | null>(null);
Expand Down Expand Up @@ -87,6 +89,12 @@ const IntlTelInput = forwardRef(function IntlTelInput({
}
};
}, [update]);

useEffect(() => {
if (itiRef.current && disabled !== undefined) {
itiRef.current.setDisabled(disabled);
}
}, [disabled]);

return (
<input
Expand Down
8 changes: 8 additions & 0 deletions react/src/intl-tel-input/reactWithUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type ItiProps = {
usePreciseValidation?: boolean;
initOptions?: SomeOptions;
inputProps?: object;
disabled?: boolean | undefined;
};

export type IntlTelInputRef = {
Expand All @@ -32,6 +33,7 @@ const IntlTelInput = forwardRef(function IntlTelInput({
usePreciseValidation = false,
initOptions = {},
inputProps = {},
disabled = undefined,
}: ItiProps, ref: React.ForwardedRef<IntlTelInputRef>) {
const inputRef = useRef<HTMLInputElement | null>(null);
const itiRef = useRef<Iti | null>(null);
Expand Down Expand Up @@ -88,6 +90,12 @@ const IntlTelInput = forwardRef(function IntlTelInput({
}
};
}, [update]);

useEffect(() => {
if (itiRef.current && disabled !== undefined) {
itiRef.current.setDisabled(disabled);
}
}, [disabled]);

return (
<input
Expand Down

0 comments on commit d7db453

Please sign in to comment.