[RFC] TextArea: express a native length cap independently of the grapheme counter
Problem Statement
An SSR form can accept text before hydration or with JavaScript disabled. Its caller may want a native maxlength on the textarea during that interval, while keeping Astryx's grapheme counter and server validation as separate policies. TextArea currently cannot express that distinction through its typed public API.
This is an opt-in capability request, not a bug in the existing soft counter. The current contract intentionally says maxLength warns but never blocks typing. Please preserve that default and its grapheme semantics.
Evidence of Demand
- Our SSR forms need this today. The single-line field's separate solution has already shipped; this request concerns only TextArea.
- The browser exposes this independently through
HTMLTextAreaElement.maxLength. It measures UTF-16 code units, not graphemes. - This applies to progressively enhanced forms and caller-owned storage/exchange limits, not one product's layout or copy.
Why Existing Components Don't Cover This
Inspected version: @astryxdesign/[email protected]. Also checked upstream main at ba460c0038225696888a87636845c4d50e2d6880.
Minimal SSR illustration using the existing public API:
import { renderToString } from 'react-dom/server';
import { TextArea } from '@astryxdesign/core/TextArea';
const html = renderToString(
<TextArea label="Notes" htmlName="notes" value="" maxLength={100} />,
);
// Source-derived expectation: the textarea has no maxlength attribute;
// maxLength enables the soft counter instead.
Verification boundary: this snippet is derived from reading the published declarations and implementation, not an executed reproduction. No Node SSR run, browser run, hydration test, install, or build was performed for this report.
Source evidence:
- Published
dist/TextArea/TextArea.d.ts:155–164explicitly documentsmaxLengthas a grapheme counter that does not enforce natively.TextAreaPropshas no independent native-length prop or typed textarea-attributes bag. - Published
dist/TextArea/TextArea.js:143destructuresmaxLength; the textarea at330–371never assigns it. The rest spread cannot forward a prop already consumed by the counter. - The same is visible in current source, its destructuring, and textarea rendering.
- The current component contract explicitly excludes enforcing
maxLength.
A forwarded-ref mutation runs only after mount, so cannot add the server attribute. Lowercase maxlength is not a supported typed React prop or a suitable public-API workaround. Replacing the whole field with a native textarea and rebuilding its Field/status/counter composition loses the component we are trying to reuse.
Dedupe: searched current issues and PRs, open and closed, for nativeMaxLength, htmlMaxLength, TextArea maxlength, native attributes, textareaProps, and inputProps. #5187 changes the counter's counting strategy and explicitly retains soft limits; it does not expose a native cap. #6307 and #10485 concern TextInput only. #5638/#5643 addressed autoComplete, not a general textarea-attributes hook. #849 deliberately removed the native attribute from the counter; this request does not reverse that decision.
Rough Approaches Considered
A narrow, independently typed native attribute seems sufficient. Following the API Conventions' HTML-collision rule, a possible spelling is htmlMaxLength (or another owner-approved native-attribute name such as nativeMaxLength):
// Proposed API, not currently supported:
<TextArea
label="Notes"
value={notes}
onChange={setNotes}
maxLength={100} // existing soft grapheme counter
htmlMaxLength={400} // independent native UTF-16 cap
/>
An independently typed textarea-attributes hook is another option if the system already intends that broader surface. The ask is the capability, not either specific API design.
The native prop should also work without the counter, and omission should emit no native limit. It should not silently truncate a caller-supplied controlled value or introduce a second JS enforcement engine.
SSR/hydration policy: an explicit native value should be present in server markup and the matching initial hydration render. The caller may retain it, or remove it in a subsequent React render after hydration. Our downstream policy uses the same numeric limit before hydration, accepts that emoji-heavy text hits that UTF-16 cap earlier, then removes it so hydrated enforcement uses graphemes. That lifecycle need not become Astryx behavior. A client-only mount can omit the native prop entirely.
There is no universal finite multiplier that makes a native UTF-16 cap equivalent to a grapheme limit: a grapheme can contain arbitrarily many combining marks. The two limits must be documented independently. Server-side validation remains authoritative for the chosen business rule, including requests that bypass the UI.
Accessibility Considerations
Keep the existing counter, over-limit styling, aria-describedby, aria-invalid, and threshold announcements tied to its existing grapheme count, not the native cap. No new role or keyboard interaction is needed. A native cap can stop input before the soft counter reaches its limit; callers must communicate any distinct constraint appropriately. IME, paste, and native enforcement follow browser semantics; no browser or assistive-technology behavior is claimed verified here.
Performance Considerations
One optional native attribute; no extra elements, measurement, segmentation, or automatic hydration state is required for the capability.
Pre-submission Checklist
- [x] I have read the Contributing guide
- [x] I have read the API Conventions
- [x] I have checked that existing Astryx components cannot compose to solve this
- [x] This is a general-purpose UI pattern (not specific to one product)
Hi! I'd love to work on this issue. I've gone through the problem statement and understand the distinction between the existing soft grapheme counter and the proposed native length cap.
Could you please assign this issue to me? Thanks!
Hi @cixzhang @duytbp I've explored the implementation for this RFC. I've added an independent htmlMaxLength prop while preserving the existing grapheme-based maxLength counter, along with tests (including SSR coverage), documentation updates, and a changeset.
Before I open an implementation PR, could you please confirm whether this approach and API naming align with the intended direction?
Thanks for building this. htmlMaxLength is OK as a pure pass-through to the native maxlength attribute, and nothing more: no counting, and no change to TextArea's existing length warning. Please open the PR with docs and a test.