Skip to content

[Feature] maxLength for EnrichedTextInput, including paste and dictation #732

Description

@lukasz-patalan

Is your feature request related to a problem? Please describe.

EnrichedTextInput has no maxLength, so there is no way to cap how much text a user can enter. In a form that mixes plain TextInputs with enriched ones, the same character limit usually has to apply to every field, and the enriched ones are currently the only fields where it cannot be enforced.

Doing it from JS does not really work: the value is HTML, so the limit has to be measured on parsed plain text, and the only way to enforce it is to set the value back after the fact, which resets the selection and fights the undo stack. Paste is worse still, because the text is already in the editor by the time JS sees it.

Describe the solution you'd like

A maxLength?: number prop that counts the editor's plain text, ignoring formatting, and matches TextInput semantics: typing past the limit is rejected, longer input is truncated to what still fits.

The parts that are easy to get subtly wrong:

  • Paste truncates the pasted fragment instead of being rejected, leaving whatever followed the caret intact.
  • Dictation and IME input arrive as multi character replacements and need the same truncation, not the rejection used for typing.
  • The cut point snaps outwards, so emoji, surrogate pairs and combining marks never get split.
  • Truncated text still goes through the regular editing path, so formatting, link detection and mentions keep working, and onChangeHtml / onChangeText fire with what actually ended up in the editor.

Describe alternatives you've considered

Truncating in JS after every change loses the selection and cannot handle paste. Blocking submission instead of input leaves users pasting a wall of text into a field that will then refuse to submit.

Additional context

We currently carry this as a native patch on top of the library, on both Android and iOS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions