Repository navigation
[lexical-rich-text][lexical-a11y] Feature: Announce heading changes by default in rich text - #8908
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
e6c0ac9 to
099d3bb
Compare
…appen
Adds HeadingAnnounceExtension, announcing through the existing
AriaLiveRegionExtension sink:
block becomes a heading -> 'Heading level 2'
heading stops being one -> 'Heading level 2 removed'
The markdown heading shortcut is a number-sign character followed by the space
bar. Pressing space triggers the transformation: both keystrokes are consumed
and the block type changes. For a sighted user that is obvious - the characters
disappear and the text jumps to heading size. For a screen-reader user there is
no signal at all, so the reasonable conclusion is that the document now contains
a number sign, a space, and whatever is typed next. It does not.
And when the shortcut IS intended, the only way to confirm the level today is to
move the caret out of the block and arrow back in, mid-sentence, every time.
Follows HistoryAnnounceExtension: defineExtension + namedSignals + safeCast,
depends on AriaLiveRegionExtension, config {created, destroyed, disabled} with
%s substituted for the level so the strings stay translatable, and a disabled
signal gated from an effect so a disabled announcer registers no listener.
RichTextExtension is declared as a dependency because it registers HeadingNode:
attaching a mutation listener for a node the editor has not registered throws.
This matches how AutoLinkExtension depends on LinkExtension, and
CheckListExtension on ListExtension.
Note: a level change - typing "## " straight after "# ", with no text entered -
fires both a removal and a creation. In the first block of the document the
removal is what reached the live region, so it announced "Heading level 1
removed" instead of the new level. Announce the creation; only say "removed"
when nothing replaced it.
A destroyed node is gone from the current editor state, so its level is read
from the prevEditorState that registerMutationListener provides.
Silent otherwise. Typing inside a heading, moving the caret through it, and
deleting text while the heading survives do not announce - announcing on every
keystroke would make a heading impossible to type into.
Enabled in the playground alongside HistoryAnnounceExtension and
EditorModeAnnounceExtension.
Note: HeadingNode lives in @lexical/rich-text, so this adds that as a dependency
of @lexical/a11y - the first dependency beyond @lexical/extension,
@lexical/utils and lexical. See the PR description for the placement question.
Tests: seven cases in
packages/lexical-a11y/src/__tests__/unit/HeadingAnnounceExtension.test.ts,
following the structure of the existing HistoryAnnounceExtension tests. One
asserts silence while editing inside a heading; one covers a level change.
099d3bb to
8a7141a
Compare
…is announced Announcing a heading split the surrounding edit into two undo steps, so a single undo took back only half of it. After a Markdown import the document stayed as rich text instead of returning to the Markdown code block, and Markdown.spec.mjs "can convert markdown text into rich text" failed on its undo assertion. The announcer read the new heading level with editor.read(). That call flushes any pending update before it reads, and a mutation listener runs while an update is being committed - so reading from inside one ended the update early and began a second. Reading the committed editor state directly avoids the flush. The removal branch alongside it already did this, through prevEditorState.read(). Markdown.spec.mjs passes in full, as do the @lexical/a11y unit tests.
etrepum
left a comment
There was a problem hiding this comment.
"Announcers live with their node" (extension really) is the better strategy here. This way accessibility is the default, @lexical/a11y doesn't end up bringing in all of lexical's packages as a dependency, etc.
…nto the editor Adding the heading announcer to a plain text editor stopped it building at all - "extension @lexical/plain-text conflicts with @lexical/rich-text" - because the announcer declared rich text as a dependency. Rich text is now a peer, so it is set up first when present and nothing is forced in when it is not, and the announcer registers nothing when the editor has no headings to watch.
| "sideEffects": false, | ||
| "dependencies": { | ||
| "@lexical/extension": "workspace:*", | ||
| "@lexical/rich-text": "workspace:*", |
There was a problem hiding this comment.
rich-text should depend on a11y, not vice versa
…y default in rich text The announcer moves from @lexical/a11y into @lexical/rich-text, beside HeadingNode, and RichTextExtension depends on it - so a rich text editor announces heading changes without anyone adding anything, and `disabled` switches it off. @lexical/rich-text now depends on @lexical/a11y rather than the reverse, so an announcer never drags a node package into an editor that did not ask for one.
|
Thank you — I appreciate your time, feedback and the reply. I agree, accessible by default is far preferable. |
etrepum
left a comment
There was a problem hiding this comment.
The pnpm-lock file is not updated so every CI step is failing.
| // Read the committed state directly. editor.read() flushes | ||
| // pending updates first, and a mutation listener runs during | ||
| // a commit - forcing a flush from inside one splits the | ||
| // update in two, so a single edit becomes two history | ||
| // entries and one undo only takes back half of it. | ||
| createdTag = editor | ||
| .getEditorState() | ||
| .read(() => $readHeadingTag(key)); |
There was a problem hiding this comment.
This is a lot of unnecessary commentary, editor.read('latest', …) does not flush.
There was a problem hiding this comment.
Thank you — switched to editor.read('latest', …) and removed the comment.
| // Accessibility is not opt-in: a rich text editor announces its heading | ||
| // changes unless the announcer is explicitly disabled. |
There was a problem hiding this comment.
unnecessary, the other defaults don't have multiple lines of comments talking about what they do
| // Accessibility is not opt-in: a rich text editor announces its heading | |
| // changes unless the announcer is explicitly disabled. |
There was a problem hiding this comment.
Thank you — removed.
|
The lockfile and both comments are addressed. CI hasn't run on the latest commit — it needs an approval when you have a moment. |
|
@etrepum is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page ## Description Depends on the changesets tooling in #9357. Past versions in CHANGELOG.md only list commits, so someone upgrading from an older version cannot find what broke, or how to migrate, without reading every GitHub release. Future versions get curated sections from changesets; this gives v0.23.0 to v0.52.0 the same sections. - Every version from v0.23.0 to v0.52.0 now starts with `### Breaking changes` (35 entries), `### Behavior changes` (43) and `### Deprecations` (29), each with packages and a PR link. The existing lines are kept, unchanged, under `### All changes` (the diff only adds lines). - Rule, stated in the preamble: a breaking change needs a code change (an API removed or renamed, a type that no longer checks, a call that now throws) and has `Detect:` and `Migration:`. A behavior change keeps building but behaves or renders differently and has `Verify:`. The entries come from a verified inventory of those releases, which marked each change as manual, mechanical, or runtime-only ("no type or build error points at it"). Runtime-only entries are behavior changes, except #7341 (now throws) and #8603 (a signature change), which stay breaking. - v0.50.0: the items its release notes list as "Behavior Changes to Watch" (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes; the listener return-type tightening (#8990), the new invariants (#6483) and the two items the release called breaking (#8938, #8995) stay breaking. Checked against the v0.50.0 release notes. - Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin` (#8199; present in the v0.41.0 tag, absent in v0.42.0). - Deprecations come from a pass over every `@deprecated` tag added between consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag and attributed with `git log -S`. Each has `Replacement:` and `Removal:`: the version that removed it, "no earlier than v0.53.0" for the ones #9316 removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`), and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed. - Entries that mixed a breaking change and a deprecation are split with no double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated aliases, so they are listed under Deprecations alone. - `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade all packages together, read CHANGELOG.md between your version and the target (also at `node_modules/lexical/CHANGELOG.md`) or print that range, and a copy-paste `AGENTS.md` snippet that points coding agents at the installed changelog. Nothing is installed automatically. - The repository CHANGELOG.md test checks every backfilled entry: `Detect:` and `Migration:` on breaking changes, `Verify:` on behavior changes, `Replacement:` and a valid `Removal:` on deprecations, a PR link on all. ## Test plan ### Before ``` $ pnpm run changelog:range -- --from 0.49.0 --breaking Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full. No breaking changes, behavior changes or deprecations recorded after 0.49.0. ``` ### After ``` $ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md 1412 0 CHANGELOG.md $ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### ' ## v0.50.0 (2026-09-02) ### Breaking changes ### Behavior changes ### Deprecations ## v0.51.0 (2026-09-17) ### Breaking changes ### Deprecations ## v0.52.0 (2026-09-27) ### Breaking changes ### Behavior changes ### Deprecations $ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json # (kind, [(pr, behavior)]) [('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])] $ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts Tests 63 passed (63) $ pnpm -C packages/lexical-website run docusaurus build [SUCCESS] Generated static files in "build". ```
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page ## Description Depends on the changesets tooling in #9357. Past versions in CHANGELOG.md only list commits, so someone upgrading from an older version cannot find what broke, or how to migrate, without reading every GitHub release. Future versions get curated sections from changesets; this gives v0.23.0 to v0.52.0 the same sections. - Every version from v0.23.0 to v0.52.0 now starts with `### Breaking changes` (35 entries), `### Behavior changes` (43) and `### Deprecations` (29), each with packages and a PR link. The existing lines are kept, unchanged, under `### All changes` (the diff only adds lines). - Rule, stated in the preamble: a breaking change needs a code change (an API removed or renamed, a type that no longer checks, a call that now throws) and has `Detect:` and `Migration:`. A behavior change keeps building but behaves or renders differently and has `Verify:`. The entries come from a verified inventory of those releases, which marked each change as manual, mechanical, or runtime-only ("no type or build error points at it"). Runtime-only entries are behavior changes, except #7341 (now throws) and #8603 (a signature change), which stay breaking. - v0.50.0: the items its release notes list as "Behavior Changes to Watch" (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes; the listener return-type tightening (#8990), the new invariants (#6483) and the two items the release called breaking (#8938, #8995) stay breaking. Checked against the v0.50.0 release notes. - Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin` (#8199; present in the v0.41.0 tag, absent in v0.42.0). - Deprecations come from a pass over every `@deprecated` tag added between consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag and attributed with `git log -S`. Each has `Replacement:` and `Removal:`: the version that removed it, "no earlier than v0.53.0" for the ones #9316 removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`), and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed. - Entries that mixed a breaking change and a deprecation are split with no double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated aliases, so they are listed under Deprecations alone. - `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade all packages together, read CHANGELOG.md between your version and the target (also at `node_modules/lexical/CHANGELOG.md`) or print that range, and a copy-paste `AGENTS.md` snippet that points coding agents at the installed changelog. Nothing is installed automatically. - The repository CHANGELOG.md test checks every backfilled entry: `Detect:` and `Migration:` on breaking changes, `Verify:` on behavior changes, `Replacement:` and a valid `Removal:` on deprecations, a PR link on all. ## Test plan ### Before ``` $ pnpm run changelog:range -- --from 0.49.0 --breaking Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full. No breaking changes, behavior changes or deprecations recorded after 0.49.0. ``` ### After ``` $ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md 1412 0 CHANGELOG.md $ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### ' ## v0.50.0 (2026-09-02) ### Breaking changes ### Behavior changes ### Deprecations ## v0.51.0 (2026-09-17) ### Breaking changes ### Deprecations ## v0.52.0 (2026-09-27) ### Breaking changes ### Behavior changes ### Deprecations $ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json # (kind, [(pr, behavior)]) [('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])] $ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts Tests 63 passed (63) $ pnpm -C packages/lexical-website run docusaurus build [SUCCESS] Generated static files in "build". ```
…ing announcer Impact: undoing a quote conversion says "Block quote removed" rather than "Undone", so a screen reader user is told what changed and not merely that something was reversed. Redo says "Block quote" for the same reason. This reverses the HISTORIC_TAG guard added in the previous commit, which left undo to HistoryAnnounceExtension. Two things argue against that guard: - "Undone" does not say what was undone. Having pressed the key, the user already knows an undo happened; what they cannot see is which block changed, which is the part worth speaking. - It made quotes disagree with headings. HeadingAnnounceExtension, merged in meta#8908, already announces "Heading level 3 removed" when an undo removes a heading, not "Undone". Suppressing quotes on the same tag would have shipped two announcers in one package behaving differently. Measured rather than assumed: recording every write to the live region through a MutationObserver, rather than reading its final text, shows one message survives each commit. With the guard, undo of a quote gave ["Undone"]; without it, ["Block quote removed"] — matching the heading announcer's ["Heading level 3 removed"] for the same action. The better answer is for both messages to reach the user, something like "Undone, block quote removed". That needs the live region to compose messages within a commit rather than keep the last, and a way to tell undo from redo, since both carry HISTORIC_TAG. It would change the merged heading announcer too, so it belongs in its own PR rather than here. The quote-to-heading fix from the previous commit is unchanged and still tested. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…havior changes and deprecations into CHANGELOG.md for v0.23 to v0.52, add an Upgrading page Depends on the changesets tooling in #9357. Past versions in CHANGELOG.md only list commits, so someone upgrading from an older version cannot find what broke, or how to migrate, without reading every GitHub release. Future versions get curated sections from changesets; this gives v0.23.0 to v0.52.0 the same sections. - Every version from v0.23.0 to v0.52.0 now starts with `### Breaking changes` (35 entries), `### Behavior changes` (43) and `### Deprecations` (29), each with packages and a PR link. The existing lines are kept, unchanged, under `### All changes` (the diff only adds lines). - Rule, stated in the preamble: a breaking change needs a code change (an API removed or renamed, a type that no longer checks, a call that now throws) and has `Detect:` and `Migration:`. A behavior change keeps building but behaves or renders differently and has `Verify:`. The entries come from a verified inventory of those releases, which marked each change as manual, mechanical, or runtime-only ("no type or build error points at it"). Runtime-only entries are behavior changes, except #7341 (now throws) and #8603 (a signature change), which stay breaking. - v0.50.0: the items its release notes list as "Behavior Changes to Watch" (#8765, #8908, #8884, #9059, #9061, #8940, #8283) are behavior changes; the listener return-type tightening (#8990), the new invariants (#6483) and the two items the release called breaking (#8938, #8995) stay breaking. Checked against the v0.50.0 release notes. - Added the v0.42.0 removal of `@lexical/react/LexicalContextMenuPlugin` (#8199; present in the v0.41.0 tag, absent in v0.42.0). - Deprecations come from a pass over every `@deprecated` tag added between consecutive tags v0.22.0 to v0.52.0, each checked against the previous tag and attributed with `git log -S`. Each has `Replacement:` and `Removal:`: the version that removed it, "no earlier than v0.53.0" for the ones #9316 removes after v0.52.0, otherwise "not scheduled". Skipped: tags that only moved (`trimTextContentFromAnchor`, deprecated before v0.23.0) or restated earlier ones (v0.46.0 `HorizontalRulePlugin`, v0.51.0 `getScrollParent`), and the v0.47.0 `applyFormatToDom` deprecation that v0.48.0 reversed. - Entries that mixed a breaking change and a deprecation are split with no double counting (#7357, #8360, #8661); #8350 and #8662 only deprecated aliases, so they are listed under Deprecations alone. - `docs/upgrading.md` ("Upgrading" in the sidebar) is a short page: upgrade all packages together, read CHANGELOG.md between your version and the target (also at `node_modules/lexical/CHANGELOG.md`) or print that range, and a copy-paste `AGENTS.md` snippet that points coding agents at the installed changelog. Nothing is installed automatically. - The repository CHANGELOG.md test checks every backfilled entry: `Detect:` and `Migration:` on breaking changes, `Verify:` on behavior changes, `Replacement:` and a valid `Removal:` on deprecations, a PR link on all. ``` $ pnpm run changelog:range -- --from 0.49.0 --breaking Note: v0.50.0, v0.51.0, v0.52.0 have no curated sections (the changelog only lists their commits), so --breaking cannot show what changed there. Run without --breaking to read them in full. No breaking changes, behavior changes or deprecations recorded after 0.49.0. ``` ``` $ git diff --numstat --diff-algorithm=patience HEAD~1 -- CHANGELOG.md 1412 0 CHANGELOG.md $ pnpm run changelog:range -- --from 0.49.0 --breaking | grep '^## \|^### ' $ pnpm run changelog:range -- --from 0.49.0 --to 0.50.0 --breaking --json # (kind, [(pr, behavior)]) [('breaking', [(8938, False), (8995, False), (8990, False), (6483, False)]), ('behavior', [(8765, True), (8908, True), (8884, True), (9059, True), (9061, True), (8940, True), (8283, True)]), ('deprecation', [(8918, False)])] $ pnpm run test-unit scripts/__tests__/unit/changelog.test.ts scripts/__tests__/unit/changesets.test.ts Tests 63 passed (63) $ pnpm -C packages/lexical-website run docusaurus build [SUCCESS] Generated static files in "build". ```
Why
The markdown heading shortcut is two keystrokes: a number-sign character
(
#), then the space bar. Pressing space is what triggers thetransformation — the editor deletes both characters and converts the block to a
heading. Nothing is inserted; both keystrokes are consumed.
For a sighted user that is obvious: the
#and the space disappear and the textjumps to heading size. For a screen-reader user there is currently no signal at
all.
So a blind user presses
#, presses space, and hears nothing. Their reasonableconclusion is that the document now literally contains a number sign, then a
space, then whatever they type next — because that is exactly what they typed and
nothing told them otherwise. In reality those two keystrokes are gone and the
block is now a level-1 heading.
The user's mental model of their own document is wrong, and nothing in the
editor corrects it. The transformation is invisible precisely because it is
visual.
And if the user did intend to create a heading, they still cannot confirm it
without leaving what they are doing: move the caret out of the block, arrow back
into it, and wait for the screen reader to read the heading level on entry. That
is a costly interruption mid-sentence, and it has to be repeated every time
they want to be sure.
Announcing at the moment the block changes gives immediate confirmation while
typing — no navigation, no interruption, no doubt about what the editor just
did. Removal is announced for the same reason: backspacing out of a heading is
equally silent today.
@lexical/a11yalready announces undo, redo and editable/read-only. Thisextends that to document structure, starting with the structure that matters
most for navigation.
What
Announces heading block-type changes through the editor's aria live region:
HeadingAnnounceExtensionlives in@lexical/rich-textbesideHeadingNode,and
RichTextExtensiondepends on it — heading changes are announced bydefault.
Shape
Follows
HistoryAnnounceExtensionexactly:defineExtension+namedSignals+safeCastdependencies: [AriaLiveRegionExtension]{created, destroyed, disabled}—%ssubstituted with the level, sothe strings stay translatable
disabledsignal, gated from aneffectso a disabled announcerregisters no listener at all
It sits alongside
RichTextImportExtension, so@lexical/rich-textdepends on@lexical/a11yrather than the reverse.A destroyed node is gone from the current editor state, so its level is read
from the
prevEditorStatethatregisterMutationListenerprovides.What this does not announce
Only the two transitions above. Typing inside a heading, moving the caret
through it, and deleting text while the heading survives are all silent —
announcing on every keystroke would make a heading impossible to type into.
Tests
Seven cases in
packages/lexical-rich-text/src/__tests__/unit/HeadingAnnounceExtension.test.ts,following the structure of the existing
HistoryAnnounceExtensiontests:configExtensionoverridescreated/destroyedstringsdisabledThe silence case matters: nothing otherwise prevents an announcement on every
keystroke, so that regression would be invisible.