software-mansion / software-mansion/react-native-enriched-html

[Feature] maxLength for EnrichedTextInput, including paste and dictation

Open
#732 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C
Stars
1.4k
Forks
66
Avg merge
4d 19h
Merged PRs (30d)
11

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the native EnrichedTextInput implementations for Android and iOS, where the existing native patch is carried. Trace typing, paste, dictation, and IME replacement through the regular editing path, then verify that plain-text limits, grapheme-safe truncation, formatting, and onChangeHtml/onChangeText behavior match the requested semantics on both platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native
Domain
mobile
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.