fix: Values always added from first input even when another input is selected or focused #448
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaced the
const getOTPValue = () => (value ? value.toString().split('') : []);
function withuseRef
hook to save the state of the current otp array to match each input box with its index of the array to fix the issue of when adding new value it always starts from the first input box even when another input is selected or focused.Also, add an if check to check at each rerender if the value is empty string then reset the value of the otp array.
Moreover, removed the activeInput subtract from numInputs in
and removed the check for pos >= activeInput in
to make pasting start from the first input even if any other input is selected or focused
PS: I don't know if the copy paste behavior for always starting from the first input is intended or not but I felt that it make sense to paste the whole copied string across all the input not just starting from selected one.