fix(OTPInput): accept a code delivered by SMS autofill or a password manager - #668
Merged
Conversation
…manager Autofill and password managers insert the whole code at once and fire `input`, never `paste` — and the `input` handler only accepted `value.length === 1`, while every slot carried `maxlength=1` and `autocomplete="one-time-code"`. The code therefore stayed in the slot that received it (or was truncated to a single character), the hidden form control kept its old value, and neither `change` nor `complete` fired — so the form submitted an empty OTP and auto-submit flows never ran. - A multi-character value arriving in any slot is now spread across the field through the same path as a paste; a value at least as long as the field is treated as a complete code and fills from the first slot. - The hidden value is read back from the slots, so a partial paste no longer discards characters already entered (`9` + paste `87` => `987`, was `87`). - Only the first slot advertises `autocomplete="one-time-code"`; the rest are `off`, so autofill targets a single field. The first slot accepts the whole code while empty and shrinks back to one character once filled, and `clear()` / `reset()` restore that capacity. - Slots gained `enterkeyhint`, `autocorrect="off"` and `spellcheck="false"`. Backport of the v6 fix (#665); the attribute recipe follows Base UI's OTP field, which uses the same one-input-per-slot architecture we do. Eight regression tests, all red before the fix.
The fix adds ~0.6 kB gzip to the unminified bundles and ~0.15 kB to the minified ones, and the previous budgets left 0.06-0.26 kB of headroom.
Coverage Report for CI Build 30760316824Coverage increased (+0.03%) to 94.677%Details
Uncovered Changes
Coverage Regressions3 previously-covered lines in 1 file lost coverage.
Coverage Stats💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport of the v6 fix (#665) to the v5 line, verified against the v5 sources rather than assumed.
The bug
Autofill and password managers insert the whole code at once and fire
input, neverpaste— and theinputhandler only acceptedvalue.length === 1, while every slot carriedmaxlength=1andautocomplete="one-time-code". The code therefore stayed in the slot that received it (or was truncated to a single character by the browser), the hidden form control kept its old value, and neitherchangenorcompletefired — so the form submitted an empty OTP and auto-submit flows never ran.The fix
_distributeChars); a value at least as long as the field is treated as a complete code and fills from the first slot, whichever slot is focused.9+ paste87→987, was87).autocomplete="one-time-code"; the rest areoff, so autofill targets a single field. The first slot accepts the whole code while empty and shrinks back to one character once filled;clear()andreset()restore that capacity.enterkeyhint,autocapitalize="off",autocorrect="off"andspellcheck="false".The attribute recipe follows Base UI's OTP field, which uses the same one-input-per-slot architecture we do.
Tests
Eight regression tests, all red before the fix, plus the amended attribute test. Full karma suite green (3017).
Bundle budgets
The fix adds ~0.6 kB gzip to the unminified JS bundles and ~0.15 kB to the minified ones; the previous budgets left 0.06–0.26 kB of headroom, so
.bundlewatch.config.jsonis raised in a separate commit.Parity
The same fix ships for React (
coreui-react-pro), Vue (coreui-vue-pro) and Angular (coreui-angular-pro) on the same branch name.