Repository navigation
feat(lab): add maxLength character counter to RichTextEditor - #4502
Merged
Merged
Conversation
potatowagon
requested review from
cixzhang,
ejhammond and
imdreamrunner
as code owners
July 29, 2026 05:45
|
Deployment failed with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
This was referenced Jul 29, 2026
cixzhang
approved these changes
Jul 30, 2026
potatowagon
enabled auto-merge (squash)
July 30, 2026 06:07
Adds a `maxLength?: number` prop. When set, a character counter (current/max) is rendered below the editor, mirroring the TextArea pattern: - Counter shows plain-text content length / maxLength. - Turns red (error styling) when the count exceeds the limit. - Does NOT enforce the limit natively (visual only), matching TextArea. - aria-live region announces remaining/over-limit chars past 80% of the limit. - Counter is associated with the editor via aria-describedby. The count is tracked by a small internal CharCountPlugin that reads $getRoot().getTextContent().length on mount and via registerUpdateListener — same in-composer pattern as AutoFocusOnMount. - Updated RichTextEditor.doc.mjs props table - Added WithCharacterLimit storybook story + maxLength control - Added 4 unit tests (no counter when unset, seeded count, over-limit, aria)
… counter The maxLength CharCountPlugin imported $getRoot from the top-level 'lexical' package as a runtime value. That runtime import made the sandbox Next build resolve and transpile lexical's raw src/*.ts (which uses 'declare' class fields), which Next's Babel loader rejects — breaking build-sandbox: SyntaxError: The 'declare' modifier is only allowed when the 'allowDeclareFields' option ... is enabled. (lexical/src/LexicalEditor.ts, LexicalNode.ts, ...) Replace $getRoot()/getTextContent() with editor-instance methods that need no top-level 'lexical' value import: registerTextContentListener for updates and getRootElement().textContent for the initial seeded count. The 'lexical' import is now type-only again (erased by Babel), matching the pre-existing pattern. No behavior change to the counter; test/build-storybook were already green.
potatowagon
force-pushed
the
navi/feat/richtext-maxlength
branch
from
July 30, 2026 06:29
7aa4db8 to
6356b59
Compare
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This was referenced Jul 30, 2026
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
maxLength?: numberprop to the experimentalRichTextEditor(@astryxdesign/lab). When set, a character counter (current/max) renders below the editor.Why
Parity gap with TextArea (and with EPS
RichTextArea, which this component is intended to eventually replace): there was no way to show a character limit / counter. This adds it following the exact TextArea pattern so the two inputs behave consistently.How
maxLengthprop. When set:current/max) renders below the editor, right-aligned, using the same styles/tokens as TextArea's counter.--color-error) when the plain-text length exceedsmaxLength.maxLengthis advisory; submit-time validation is the consumer's job).aria-live="polite"region (viaVisuallyHidden) announces "N characters remaining" / "N over limit" once past 80% of the limit (COUNTER_WARNING_THRESHOLD, same as TextArea).aria-describedby.CharCountPluginthat reads$getRoot().getTextContent().lengthon mount (sodefaultValue-seeded content counts) and on everyregisterUpdateListener— the same in-composer pattern as the existingAutoFocusOnMountplugin.Docs / stories / tests (SYNC contract)
RichTextEditor.doc.mjs— addedmaxLengthto the props table.RichTextEditor.stories.tsx— added aWithCharacterLimitstory + amaxLengthcontrol.RichTextEditor.test.tsx— added 4 tests: no counter when unset, counter reflects seeded length, over-limit styling + aria announcement, andaria-describedbyassociation.Testing
CI runs the full build/typecheck/lint/test. (Authored on a devserver without a local pnpm toolchain, so relying on CI for the checks — happy to iterate on any red signal.)
Notes
main(includes the mergedtransformersprop from feat(lab): expose transformers prop on RichTextEditor #4416).