feat: maxLength - #755
Conversation
There was a problem hiding this comment.
Pull request overview
Adds maxLength?: number support to EnrichedTextInput across Web/iOS/Android, enforcing the limit based on the editor’s plain text (ignoring ZWS) across typing, paste, and programmatic entry points, with new e2e coverage and demo screens.
Changes:
- Web: introduce a ProseMirror/Tiptap max-length extension and wire the new prop into the web editor setup.
- Native: expose
maxLengththrough the RN spec/manager and enforce it in iOS (utilities + insertion points) and Android (InputFilter + insertion helpers). - Tooling/docs/tests: document the prop, add example/test screens, and add Playwright + Maestro e2e coverage.
Reviewed changes
Copilot reviewed 24 out of 38 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/web/pmPlugins/MaxLengthPlugin.ts | New Tiptap/ProseMirror plugin that trims inserted ranges when doc exceeds maxLength. |
| src/web/EnrichedTextInput.tsx | Wires maxLength into the web editor via the new plugin. |
| src/types.ts | Adds maxLength?: number to EnrichedTextInputProps. |
| src/spec/EnrichedTextInputNativeComponent.ts | Exposes maxLength to native via codegen (default -1). |
| src/native/EnrichedTextInput.tsx | Passes maxLength prop through to the native component. |
| ios/utils/MaxLengthUtils.mm | Adds iOS utilities for plain-length counting and safe truncation (composed characters). |
| ios/utils/MaxLengthUtils.h | Declares the new iOS max-length helper API. |
| ios/styles/MentionStyle.mm | Makes mention insertion respect remaining capacity and clamps mention range when truncated. |
| ios/inputHtmlParser/InputHtmlParser.mm | Truncates parsed HTML processing results (text/styles/alignments) to capacity and truncates fallback raw insertion. |
| ios/EnrichedTextInputView.mm | Applies maxLength config updates; truncates defaultValue/setValue; enforces maxLength in typing path; clamps link/image insertions. |
| ios/enrichedInputTextView/EnrichedInputTextView.mm | Truncates pasted plain text fragments to remaining capacity. |
| ios/config/EnrichedConfig.mm | Stores and normalizes maxLength in config (<0 => unlimited). |
| ios/config/EnrichedConfig.h | Defines EnrichedMaxLengthUnlimited and adds config getter/setter. |
| docs/INPUT_API_REFERENCE.md | Documents the new maxLength prop behavior and platforms. |
| apps/example/src/screens/TestScreen.tsx | Adds UI controls to toggle maxLength in the native example app. |
| apps/example-web/src/testScreens/TestMaxLength.tsx | Adds a dedicated web test screen exercising maxLength across entry points. |
| apps/example-web/src/RouteSelector.tsx | Adds routing to the new /test-max-length web test screen. |
| android/src/main/java/com/swmansion/enriched/textinput/utils/MaxLengthFilter.kt | Adds maxLength grapheme-safe truncation helpers and an InputFilter enforcing the limit. |
| android/src/main/java/com/swmansion/enriched/textinput/utils/EnrichedSpannable.kt | Adds helper to replace/insert while reporting actual inserted length (post-filter). |
| android/src/main/java/com/swmansion/enriched/textinput/styles/ParametrizedStyles.kt | Updates link/image/mention insertion to respect maxLength shortening/rejection. |
| android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputViewManager.kt | Adds @ReactProp(maxLength) plumbing to the Android manager. |
| android/src/main/java/com/swmansion/enriched/textinput/EnrichedTextInputView.kt | Installs maxLength filter and truncates pasted fragments to preserve post-caret content. |
| .playwright/tests/maxLength.spec.ts | Adds Playwright e2e tests covering typing/paste/selection replace/link/mention/image behaviors. |
| .maestro/scripts/setup-android-emulator.sh | Adjusts emulator port used by Maestro setup script. |
| .maestro/enrichedInput/flows/max_length.yaml | Adds Maestro flow validating native maxLength behavior (typing/paste/set value/link/mention). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This reverts commit 5856dda.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 24 out of 38 changed files in this pull request and generated 1 comment.
Suppressed comments (4)
Previously missed (3) — in code that hasn't changed since the last review.
ios/utils/MaxLengthUtils.mm:66
cutIndexIn:capacity:can return an index that makes[truncate:toCapacity:]exceed the requestedcapacityfor composed characters (e.g. surrogate-pair emoji), because it snaps the cut point forward to the end of the composed sequence whileplainLengthOf:counts UTF-16 code units. To keep the post-condition “plainLength(truncated) <= capacity”, snap the cut point inward to the start of the composed sequence instead.
src/web/pmPlugins/MaxLengthPlugin.ts:62- The function-level comment says the cut point “snaps outward”, but the implementation cuts before the next grapheme segment when it would overflow (
units + segmentUnits > keep). Consider rewording the comment to avoid suggesting that truncation may exceedkeep.
src/types.ts:642 - Docstring wording: “If inserted content doesn't meet this limit” reads as if shorter content would be truncated. This should say “exceeds this limit”.
ios/EnrichedTextInputView.mm:2064
- When
truncate()returns an empty string, this method returns YES without applying any change. That blocks pure deletions whencapacityis negative (e.g. maxLength reduced below current content), and also prevents replacing a non-empty selection with “nothing” (which should still delete the selection). Allow emptyreplacementTextto fall through, and if truncation yields an empty string whilerange.length > 0, apply the deletion explicitly.
NSString *truncated = [MaxLengthUtils truncate:text toCapacity:capacity];
if (truncated.length == 0) {
return YES;
}
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Summary
Closes #732.
Provided the implementation of the
maxLengthprop to theEnrichedTextInputcomponent.EnrichedTextInput's content will be limited to the given number of characterssetValue,defaultValue, typing, pasting content or programmatically viaref.setImage(),ref.setImage(),ref.setLink()Test Plan
There's an available interface on mobile on the
TestScreenand under/test-max-lengthURL on web.Compatibility
Checklist