Skip to content

Commit

Permalink
fix: Only the last two digits can be deleted via BNP when input is no…
Browse files Browse the repository at this point in the history
…t focused
  • Loading branch information
truph01 committed Oct 14, 2024
1 parent 4a3f2da commit 3f86b0f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/MagicCodeInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ function MagicCodeInput(
const indexBeforeLastEditIndex = editIndex === 0 ? editIndex : editIndex - 1;

const indexToFocus = numbers.at(editIndex) === CONST.MAGIC_CODE_EMPTY_CHAR ? indexBeforeLastEditIndex : editIndex;
const formElement = inputRefs.current as HTMLFormElement | null;
(formElement?.[indexToFocus] as HTMLInputElement)?.focus();
if (indexToFocus !== undefined) {
lastFocusedIndex.current = indexToFocus;
inputRefs.current?.focus();
}
onChangeTextProp(value.substring(0, indexToFocus));

return;
Expand Down Expand Up @@ -314,6 +316,7 @@ function MagicCodeInput(
onChangeTextProp(composeToString(numbers));

if (newFocusedIndex !== undefined) {
lastFocusedIndex.current = newFocusedIndex;
inputRefs.current?.focus();
}
}
Expand Down

0 comments on commit 3f86b0f

Please sign in to comment.