Repository navigation
fix(lab): RichTextEditor Tab keyboard trap — Escape then Tab moves focus - #4380
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsRichTextEditor (@astryxdesign/lab) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
6cbadb2 to
f1cff08
Compare
|
@potatowagon can you help take a look :) |
ReviewSolid, ship-worthy. Correct WCAG 2.1.2 fix, well-tested (ran locally, 42/42 pass), no regressions found. Traced the command-priority reasoning against Lexical's actual dispatch order — it holds up. A few minor items below, none blocking. ✅ Verified correct
🟡 Minor
🔵 Nits
🔎 Edge cases considered — all OK
|
cixzhang
left a comment
There was a problem hiding this comment.
I think accessibility updates look good but I'm not sure about the changes to the build package. This is shipped publically and used mainly to split the StyleX build for layering. It should be agnostic to libraries outside of core.
| * than resolving `lexical/package.json` (not export-mapped). Returns null when | ||
| * lexical isn't installed so the alias is simply omitted. | ||
| */ | ||
| function resolveLexicalDist() { |
There was a problem hiding this comment.
Seems odd to need this in the build which might not have anything to do with lexical. Was this to solve some issue unrelated to accessibility?
There was a problem hiding this comment.
It was needed by this PR, not unrelated: the trap fix adds runtime imports from lexical (KEY_TAB_COMMAND, KEY_ESCAPE_COMMAND, etc.), and withAstryx's issuer-scoped source-condition rule makes any bare lexical request issued from an astryx module resolve to lexical's raw TS source, whose declare class fields the sandbox Babel pipeline rejects. Before this PR, lab only had type-only imports from lexical, so the problem never surfaced.
On the placement, agreed -- the shipped build package should stay agnostic to libraries outside core. The alias is now gone from packages/build entirely (byte-identical to main, alias tests and its changeset removed) and lives in apps/sandbox/next.config.mjs instead, with the same issuer-scoped shape so only astryx-issued requests are pinned. App-local is sufficient because @astryxdesign/lab is private: no external withAstryx consumer can ever build lab from source, so the sandbox is the only place this resolution path exists.
f1cff08 to
145c0f6
Compare
|
@cixzhang Addressed -- |
…SM output The RichTextEditor keyboard-trap fix needs runtime command imports from 'lexical'. withAstryx's issuer-scoped source-condition rule makes those resolve to lexical's raw TS (declare class fields), which the sandbox Babel pipeline rejects. Pin lexical$ to dist/Lexical.mjs in the sandbox app config — app-local because @astryxdesign/lab is private, so no external withAstryx consumer can hit this; the shared build package stays agnostic to libraries outside core.
145c0f6 to
0dd94dd
Compare
|
Rebased onto current main over the toolbar (#4551), link-support (#4670), and serializer (#4544) work -- the conflicts were import-merges only; the trap plugin, its command priorities, and the tests are unchanged. eslint/prettier pass locally; vitest for this branch needs the new |
RichTextEditor's input wrapper spread `themeProps('rich-text-editor', ...)`
and then overwrote it with both `stylex.props(...)` and
`className={className}`. Each of those carries its own `className`, so React
kept only the last one: the stable `astryx-rich-text-editor` class never
reached the DOM, and with it went every StyleX class on the wrapper — border,
padding, disabled and status styling — plus the `xstyle` passthrough. Merged
through `mergeProps` instead, so the theme target, the StyleX classes and any
consumer `className`/`style` all survive.
The ChatSendButton half of this change landed separately on main in #4634
(`fix(Chat): add missing themeProps and fix className clobber`) with the same
`mergeProps` call, so only its regression test remains here.
The changeset goes with it: what is left changes `@astryxdesign/lab` only,
which is `private: true` / canary-only and so cannot be named in changeset
frontmatter (`check:changesets` rejects it), matching how other lab-only
fixes land (#4670, #4550, #4380, #4891).
@cixzhang
RichTextEditor's input wrapper spread `themeProps('rich-text-editor', ...)`
and then overwrote it with both `stylex.props(...)` and
`className={className}`. Each of those carries its own `className`, so React
kept only the last one: the stable `astryx-rich-text-editor` class never
reached the DOM, and with it went every StyleX class on the wrapper — border,
padding, disabled and status styling — plus the `xstyle` passthrough. Merged
through `mergeProps` instead, so the theme target, the StyleX classes and any
consumer `className`/`style` all survive.
The ChatSendButton half of this change landed separately on main in #4634
(`fix(Chat): add missing themeProps and fix className clobber`) with the same
`mergeProps` call, so only its regression test remains here.
The changeset goes with it: what is left changes `@astryxdesign/lab` only,
which is `private: true` / canary-only and so cannot be named in changeset
frontmatter (`check:changesets` rejects it), matching how other lab-only
fixes land (#4670, #4550, #4380, #4891).
@cixzhang
RichTextEditor's input wrapper spread `themeProps('rich-text-editor', ...)`
and then overwrote it with both `stylex.props(...)` and
`className={className}`. Each of those carries its own `className`, so React
kept only the last one: the stable `astryx-rich-text-editor` class never
reached the DOM, and with it went every StyleX class on the wrapper — border,
padding, disabled and status styling — plus the `xstyle` passthrough. Merged
through `mergeProps` instead, so the theme target, the StyleX classes and any
consumer `className`/`style` all survive.
The ChatSendButton half of this change landed separately on main in #4634
(`fix(Chat): add missing themeProps and fix className clobber`) with the same
`mergeProps` call, so only its regression test remains here.
The changeset goes with it: what is left changes `@astryxdesign/lab` only,
which is `private: true` / canary-only and so cannot be named in changeset
frontmatter (`check:changesets` rejects it), matching how other lab-only
fixes land (#4670, #4550, #4380, #4891).
@cixzhang
meta#4380 pinned bare lexical imports issued from @astryxdesign modules to lexical's built ESM: lab's RichTextEditor imported lexical, and withAstryx's `source` condition sent it to lexical's raw TS. meta#4678 moved the editor into @astryxdesign/richtext, which the sandbox does not depend on, and left the alias behind. Nothing the sandbox compiles imports lexical, @lexical/* or richtext, and the build output contains no lexical code with or without the alias. Remove it, along with the lexical devDependency the earlier commit declared for it.
Summary
RichTextEditor(lab) always registers Lexical'sTabIndentationPlugin, which rebinds Tab/Shift+Tab to indent/outdent andpreventDefault()s the keydown. A keyboard-only user who tabs into the editor cannot tab out again -- a serious WCAG 2.1.2 (No Keyboard Trap) violation. Found as finding #3 of the a11y scan; this is the companion to the CodeEditor Tab-trap fix (same UX pattern: keep Tab indentation, add an Escape-then-Tab exit).Tab indentation itself is worth keeping -- it is how list/quote nesting works -- so instead of removing it, this PR adds a standard escape:
aria-describedby, overridable/suppressible through a newtabEscapeHintprop (lab has no i18n catalog; the default-English-string-via-prop pattern matchesInfoTip'slabel).Changes
packages/lab/src/RichTextEditor/RichTextEditor.tsxTabFocusEscapePlugin, rendered alongsideTabIndentationPlugin. Lexical mechanics:TabIndentationPluginhandlesKEY_TAB_COMMANDatCOMMAND_PRIORITY_EDITOR(0), the lowest priority, and Lexical runs command listeners from highest priority down, stopping at the first that returnstrue. The new plugin registers atCOMMAND_PRIORITY_LOW(1), so it always runs first:KEY_ESCAPE_COMMAND-> arm the escape. This handler returnstrue, deliberately superseding@lexical/rich-text's default Escape handler, which callseditor.blur()and dumps focus ondocument.body(disorienting, and it would immediately disarm the escape via the blur listener below). Consumer plugins that handle Escape at a higher priority still run first.KEY_TAB_COMMAND-> if armed: disarm and returntruewithoutpreventDefault(), so the indentation handler never sees the event and the browser performs its native Tab focus navigation. If not armed: returnfalseand indentation proceeds as before.KEY_DOWN_COMMAND-> any key other than Escape/Tab/bare modifiers disarms (bareShiftis exempt so Escape then Shift+Tab can escape backwards).BLUR_COMMAND-> disarm when focus leaves the editor.tabEscapeHintprop (default:'Press Escape then Tab to move focus out of the editor.'), rendered via core'sVisuallyHiddenand appended to the contenteditable'saria-describedby. Only rendered when the editor is editable; pass''to omit.@inputupdated per the repo documentation protocol.packages/lab/src/RichTextEditor/RichTextEditor.doc.mjs-- props-table entry fortabEscapeHint(targeted insert only; file otherwise untouched).packages/lab/src/RichTextEditor/RichTextEditor.test.tsx-- 7 new tests (see below).Test plan
New tests (all driven through real keydown events on the contenteditable --
userEvent.tab()/userEvent.keyboard()respectdefaultPrevented, so they exercise the actual trap):document.activeElementout of the editor (onto the next focusable button) without indenting.Shiftkeydown does not re-arm, so Escape then Shift+Tab still escapes (asserted viadefaultPrevented).aria-describedby.tabEscapeHintis overridable and''suppresses the hint (and drops it fromaria-describedby).isReadOnly(editor is not editable, so there is no trap).Pre-fix failure confirmed: with the tests added but the component fix absent, the 5 behavior/hint tests fail exactly as expected (test 2 shows focus unable to leave the editor); tests 1 and 7 pass pre-fix, as those behaviors already existed. Post-fix: 23/23.
jsdom notes (honest limitations):
RangelacksgetBoundingClientRect, which Lexical calls when reconciling a focused collapsed selection; the test suite stubs it (returns a zeroDOMRect) inside the newdescribeblock only.keydown(which is precisely the re-arm signal the implementation uses). Focus movement itself is real:user-eventimplements Tab's focus-change behavior and honorspreventDefault, so test 2 genuinely observesactiveElementleaving the editor.editor.blur()) is intentionally replaced by the arm behavior -- focus now stays in the editor after Escape until Tab is pressed.Notes
scripts/check-changesets.mjshard-rejects@astryxdesign/lab("private/ignored and cannot be released"). Lab is canary-only (private: trueis npm's guarantee against a stable publish) and is changeset-exempt per the RFC [RFC #3899] feat(lab): experimental Lexical rich-text editor (RichTextEditor + RichTextView) #3900 landing ("Lab is canary-only and private, so no changeset is required"); CI stamps canary versions. The check script passes with no changeset in this PR.tsc --project packages/lab/tsconfig.jsonreports 7 pre-existingTS2305errors inChart/ThreeD(parseHexetc. missing from@astryxdesign/core/utils); output is byte-identical on cleanmain-- untouched by this PR.review-requiredis a human gate.Review follow-up (2026-07-31)
packages/buildis no longer touched — byte-identical tomain, alias tests and its changeset removed. Thelexical$→ built-ESM pin (needed because this fix adds runtimelexicalimports, whichwithAstryx's issuer-scopedsource-condition rule would otherwise resolve to lexical's raw TS withdeclareclass fields that the sandbox Babel pipeline rejects) now lives inapps/sandbox/next.config.mjs, with the same issuer-scoped rule shape. App-local is sufficient:@astryxdesign/labis private, so no externalwithAstryxconsumer can ever build lab from source — the shared build package stays agnostic to libraries outside core.dist/Lexical.mjsis an env-switching wrapper (process.env.NODE_ENV !== 'production' ? dev : prod), so build-time env selection is preserved.main; the conflict with the newgetHTML()/getMarkdown()imperative-ref work was in thelexicalimport block only (runtime command imports merged with$generateHtmlFromNodes+ type-only imports).vitest run packages/lab/src/RichTextEditor: 46/46 green post-merge.