[OneTimePasswordField] sync focus with controlled value updates when autoFocus is enabled #3685
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.
Description
When the OTP field is controlled and autoFocus is enabled, the component now aligns focus with the current value. This supports flows where an external input (e.g., a virtual keyboard) updates the value directly. For example, if value becomes "1", the second input is focused and ready for the next digit.
What changed
Added an effect that, on value change, focuses the input corresponding to the current value length.
This runs only when:
Why
In setups using virtual keyboards, the OTP field receives programmatic value updates and must keep the UI focus in sync so the next cell is immediately ready for entry.
Impact
No changes for uncontrolled usage or when autoFocus is false.
Backward compatible.
Tests
Updated tests to cover focus syncing on controlled value changes. Added story with "virtual keyboard-button"