Repository navigation
Fix a11y for ContentEditable - #4580
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
Hi @maximshipko! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
e059b95 to
cbf1212
Compare
| id={id} | ||
| ref={ref} | ||
| role={!isEditable ? undefined : role} | ||
| role={role} |
There was a problem hiding this comment.
I'd be inclined to say that a non-editable textbox does not require to be marked as a textbox. Lexical can be used in a transparent manner to provide the reading the experience. However, given the other aria and the fact that this is still customizable makes me think that this change is reasonable with what we have now
| aria-labelledby={ariaLabelledBy} | ||
| aria-multiline={ariaMultiline} | ||
| aria-owns={!isEditable ? undefined : ariaOwns} | ||
| {...(!isEditable ? {'aria-readonly': true} : null)} |
There was a problem hiding this comment.
Nit, I believe the use of undefined should do the same
| {...(!isEditable ? {'aria-readonly': true} : null)} | |
| aria-readonly={!isEditable ? true : undefined} |
There was a problem hiding this comment.
Good point! That is more readable 👍
cbf1212 to
5cbb23b
Compare
FYI, the documentation actually suggests to use a |
|
@moy2010, |
|
LGTM, thank you! |
## User impact Anyone using a screen reader on content rendered by `RichTextView` — a stored comment, a saved note, any persisted rich text. Lexical's `ContentEditable` applies `role="textbox"` even when the editor is not editable, and `RichTextView` passes it nothing to name itself with. Two effects: - axe reports `aria-input-field-name` (serious) on every story that mounts a view. Both instances sit in `.github/a11y-baseline.json`, so CI has been green on a live defect. - `textbox` is a widget role, so assistive technology presents the content as the field's *value* — one flat string. The heading, list and link structure this component exists to render is suppressed, which is the larger harm and the one a name would not have fixed. ## Problem and solution fit Why does the defect occur? `RichTextView` renders Lexical's `ContentEditable` with no props, and Lexical defaults `role` to `textbox` regardless of editability. Why does that harm the task? The task is reading published content. A widget role misdescribes it and flattens its structure; unnamed, it is also announced with no indication of what it is. Why does that matter? This is the read path for stored rich text, so the component's entire output is affected, and the baseline entry means nothing surfaces it. The fix says what the element is rather than patching the symptom. A view is content, so it takes no widget role — which removes the requirement for a name instead of satisfying it, and restores the structural roles. ## Expected behavior and authority The read-only *form field* case is already served: `<RichTextEditor isDisabled />` is a labelled field by construction. `RichTextView`'s own contract is its docstring — "a read-only renderer for serialized Lexical content… without any editing affordances" — i.e. content. Upstream history agrees this is a defect rather than a design choice. meta/lexical#2912 dropped the role in read mode; meta/lexical#4580 put it back only because removing it left an orphaned `aria-autocomplete="none"` that axe reports as `aria-allowed-attr`. The upstream fix is meta/lexical#9270; this change is the consumer-side fix, which is needed regardless because `lexical` is a peer dependency pinned at `^0.46.0`. ## Smallest restoration Three attributes cleared on the view's `ContentEditable`, with the reasoning recorded next to them: - `role` — `null`, not `undefined`, because Lexical applies its `textbox` default to `undefined`. - `aria-autocomplete`, `aria-readonly` — widget-only ARIA, invalid without a widget role. Clearing the role alone would trade `aria-input-field-name` for `aria-allowed-attr`. Also in scope because they are the same defect: - `README.md` used `<RichTextView label="Notes" …>`; that prop has never existed and does not type-check. Removed. - The 12 `RichTextEditor::*::aria-input-field-name` baseline entries are deleted: the audit reports 9 of them already resolved before this change, and this change resolves the rest. - The `SYNC:` header in `RichTextView.tsx` pointed at `RichTextView.test.tsx`, which does not exist; its tests live in `RichTextEditor.test.tsx`. Corrected per the repository's update protocol. `RichTextEditor` is unaffected — it already names its `ContentEditable`. ## Evidence **Reproduction before the change** — the new test against unmodified source prints the three attributes: ``` $ npx vitest run packages/richtext -t "renders content rather than a form field" FAIL packages/richtext/src/RichTextEditor.test.tsx > RichTextView > renders content rather than a form field expected document not to contain element, found <div aria-autocomplete="none" aria-readonly="true" role="textbox" Tests 1 failed | 87 skipped (88) ``` axe over the story set, on `main`: ``` $ node .github/scripts/accessibility-audit.js --baseline .github/a11y-baseline.json \ --fail-on-new --components RichTextEditor ✓ Audited: RichTextEditor / Controlled Persistence - 1 issues Audit complete: 1 total violations found 0 new, 1 baselined, 9 resolved, 156 baselined for stories outside this run ✓ RichTextEditor::Custom Transformers::aria-input-field-name ✓ RichTextEditor::Default::aria-input-field-name ... (9 baseline entries reported already resolved) ``` **Result after the change**: ``` $ node .github/scripts/accessibility-audit.js --baseline .github/a11y-baseline.json \ --fail-on-new --components RichTextEditor ✓ Audited: RichTextEditor / Default - 0 issues ... all 15 stories ... Audit complete: 0 total violations found 0 new, 0 baselined, 0 resolved, 154 baselined for stories outside this run No new accessibility violations. Gate passed. $ node .github/scripts/accessibility-audit.js ... --components RichTextView Owner route: richtext/RichTextView -> lab-richtexteditor--markdown-serializers ✓ Audited: RichTextEditor / Markdown Serializers - 1 issues 0 new, 1 baselined, 0 resolved ``` The one remaining violation on that story is `label` (critical) — the bare `<textarea>` in the story's own chrome, not the component. Its baseline entry is kept deliberately; it is a separate defect. **Representative unchanged path**: `RichTextEditor`'s own stories are in the same run above and report 0 issues throughout; the 88 richtext unit tests include its label wiring, status variants and toolbar behaviour. **Regression test**: three cases in `RichTextEditor.test.tsx` — the view has no `textbox` role and none of the widget ARIA, and list structure is reachable by role. The pre-existing "renders serialized content read-only" test asserted `getByRole('textbox')`, which encoded the defect; it now queries `[data-lexical-editor]` and keeps asserting `contenteditable="false"`. ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Testing ``` $ npx vitest run packages/richtext Test Files 1 passed (1) Tests 88 passed (88) $ pnpm run lint ✖ 82 problems (0 errors, 82 warnings) # unchanged; pre-existing no-raw-color $ pnpm run check:sync ✅ All SYNC comments are clean. ``` Real-browser states: the axe runs above drive the built Storybook in Chromium via Playwright, which is where the role and ARIA are actually observed. Full `pnpm run test` was run on this branch and on `main` at the same commit. The suite is flaky at this commit under parallelism — `main` itself reports 76 failures, this branch 64 — and the differing files are CLI template/perf tests unrelated to this change. All three that differed pass in isolation on this branch, and one of them fails in isolation on clean `main`.
This PR fix accessibility of ContentEditable in the non editable mode.
When Lexical editor is not editable, there is no

roleattribute, butaria-autocompletehas the value 'none'. That breaks our pipeline during a11y check with the critical warning:As I understand the issue, we can not have aria attributes without a valid role. So I keep the role 'textbox' for non-editable case, but at the same time set
aria-readonly="true"as suggested in doc