Skip to content

Commit

Permalink
Fix react cmp setNumber not calling update
Browse files Browse the repository at this point in the history
  • Loading branch information
jackocnr committed May 17, 2024
1 parent dcde606 commit edbafc6
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 11 deletions.
9 changes: 8 additions & 1 deletion react/build/IntlTelInput.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,14 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
const inputRef = (0, import_react.useRef)(null);
const itiRef = (0, import_react.useRef)(null);
(0, import_react.useImperativeHandle)(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
}
}),
getInput: () => inputRef.current
}));
const update = () => {
Expand Down
9 changes: 8 additions & 1 deletion react/build/IntlTelInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2762,7 +2762,14 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
const inputRef = useRef(null);
const itiRef = useRef(null);
useImperativeHandle(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
}
}),
getInput: () => inputRef.current
}));
const update = () => {
Expand Down
9 changes: 8 additions & 1 deletion react/build/IntlTelInputWithUtils.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8995,7 +8995,14 @@ var IntlTelInput = (0, import_react.forwardRef)(function IntlTelInput2({
const inputRef = (0, import_react.useRef)(null);
const itiRef = (0, import_react.useRef)(null);
(0, import_react.useImperativeHandle)(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
}
}),
getInput: () => inputRef.current
}));
const update = () => {
Expand Down
9 changes: 8 additions & 1 deletion react/build/IntlTelInputWithUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8960,7 +8960,14 @@ var IntlTelInput = forwardRef(function IntlTelInput2({
const inputRef = useRef(null);
const itiRef = useRef(null);
useImperativeHandle(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
}
}),
getInput: () => inputRef.current
}));
const update = () => {
Expand Down
6 changes: 3 additions & 3 deletions react/demo/ValidationApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const errorMap = [

const App = (): ReactElement => {
const [isValid, setIsValid] = useState<boolean | null>(null);
const [number, setNumber] = useState<string | null>(null);
const [errorCode, setErrorCode] = useState<number | null>(null);
const [notice, setNotice] = useState<string | null>(null);
const [number, setNumber] = useState<string | null>(null);
const [errorCode, setErrorCode] = useState<number | null>(null);
const [notice, setNotice] = useState<string | null>(null);

const handleSubmit = (): void => {
if (isValid) {
Expand Down
9 changes: 8 additions & 1 deletion react/demo/simple-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32489,7 +32489,14 @@
const inputRef = (0, import_react.useRef)(null);
const itiRef = (0, import_react.useRef)(null);
(0, import_react.useImperativeHandle)(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
}
}),
getInput: () => inputRef.current
}));
const update = () => {
Expand Down
9 changes: 8 additions & 1 deletion react/demo/validation-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32489,7 +32489,14 @@
const inputRef = (0, import_react.useRef)(null);
const itiRef = (0, import_react.useRef)(null);
(0, import_react.useImperativeHandle)(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
}
}),
getInput: () => inputRef.current
}));
const update = () => {
Expand Down
9 changes: 8 additions & 1 deletion react/src/intl-tel-input/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ const IntlTelInput = forwardRef(function IntlTelInput({

// expose the instance and input ref to the parent component
useImperativeHandle(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
},
}),
getInput: () => inputRef.current,
}));

Expand Down
9 changes: 8 additions & 1 deletion react/src/intl-tel-input/reactWithUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ const IntlTelInput = forwardRef(function IntlTelInput({

// expose the instance and input ref to the parent component
useImperativeHandle(ref, () => ({
getInstance: () => itiRef.current,
getInstance: () => ({
...itiRef.current,
// override setNumber to also call update, to trigger onChangeNumber etc
setNumber: (num) => {
itiRef.current?.setNumber(num);
update();
},
}),
getInput: () => inputRef.current,
}));

Expand Down

0 comments on commit edbafc6

Please sign in to comment.