withInput

Applies the full current text of the input field.

Typing, deletion, replacement, and paste all arrive as the new field text. Whitespace, dashes, dots, soft hyphens, and invisible direction marks are ignored, and Unicode decimal digits in the Basic Multilingual Plane are converted to ASCII. With OtpCharset.ALPHANUMERIC, ASCII and fullwidth Latin letters are converted to uppercase ASCII. Text containing any other character is ignored and the state is unchanged. A change to code clears the error.

The digits that this input inserts are found by comparing text with the current code (the common start and end are not new). Then:

  • One digit or fewer inserted (typing or deletion) is applied. A digit typed into a full field is ignored without a rejection.

  • Otherwise, if text holds exactly length digits in total, they replace the current code (autofill or select-all and paste, also when the new code shares its start or end with the old one).

  • Otherwise, if the inserted digits number exactly length (paste appended to the current code, as on iOS), the inserted digits replace the current code.

  • An accepted replacement reports completion, also over a different complete code. Pasting the current code again changes nothing.

  • Any other number of digits inserted at once is rejected: the state is unchanged, OtpInputResult.didComplete is false, and OtpInputResult.rejection carries the expected and received digit counts. A code is never truncated or filled in partially. A rejection means the host's configured length probably differs from what its backend sends.

Always write result.state.code back to the field, also after a rejection, so the visible text and the screen-reader value stay the same.