Skip to content

refactor(richtext): share the toolbar's link popover and format helpers - #11189

Merged
cixzhang merged 15 commits into
mainfrom
richtext-link-extraction
Nov 13, 2026
Merged

cixzhang merged 15 commits into
mainfrom
richtext-link-extraction

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Follows #8717 (toolbar link popover), now on main. #8718 (link popover plugin) and #8722 (selection toolbar) build on it.

Maintainer impact

Two RichText surfaces in review need the toolbar's link editing and inline formatting: the selection toolbar (#8722) opens the same link form from its own Link button, and the link popover plugin (#8718) renders the same URL form. Today all of it is private to RichTextEditorToolbar.tsx, so each would copy it, and the copies would drift: two link forms, two address rules.

Intended invariant

RichTextEditorToolbar behaves exactly as it does on main after #8717: the same buttons, labels, pressed states, Cmd/Ctrl+K, link popover placement, form, focus return, refused-address error, and promptForUrl path. The package entry exports nothing new.

Change

A move, with no logic change:

  • ToolbarLinkPopover.tsx: useToolbarLink(editor, {buttonRef, hasNewTabLinks, promptForUrl}), the popover's state and actions moved from the toolbar; ToolbarLinkPopover, the non-modal popover anchored to a Link button; and isInsertLink, the Cmd/Ctrl+K test.
  • linkForm.tsx: LinkForm (the toolbar's URL form, moved as-is) and REMOVE_LINK_GLYPH.
  • linkEditing.ts: toLinkHref(entered), the sanitize-or-refuse rule the toolbar's Apply used inline.
  • component:RichTextEditorToolbar names ToolbarLinkPopover.tsx and linkForm.tsx in a path-applicability:v1 block, so pnpm specs:for finds the record for both.
  • RichTextEditorToolbar.tsx exports INLINE_FORMAT_ACTIONS, InlineFormat, inlineFormatLabels, $inlineFormatsOf, formatSelection, ToolbarIconName and useToolbarIcon for other RichText modules, and uses them itself.

Originally written by @ernestt as part of #8722; ported onto #8717, now on main.

Evidence

  • Failure before the change: none; this is a move. The two callers that need these pieces are feat(richtext): an opt-in link popover plugin for the link at the caret #8718 and feat(richtext): add a selection toolbar for the editor #8722.
  • Success after the change: every RichText test passes unchanged (48 files, 783 tests), including the toolbar link tests and the public-surface test, which shows no new package export.
  • Product/runtime behavior verified unchanged: the existing toolbar link tests (popover opens on press and Cmd/Ctrl+K, applies, refuses, removes, cancels with focus and selection back in the editor, promptForUrl) run without edits. A new linkEditing.test.ts covers toLinkHref.
  • CI impact: none.

Scope

Components: RichTextEditorToolbar

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec vitest run packages/richtext/: 48 files, 783 tests pass.
  • Pre-commit hooks (lint-staged ESLint and Prettier, pnpm check:repo) pass.

ernestt and others added 7 commits November 2, 2026 11:09
RichTextEditorToolbar's Link button, and Cmd/Ctrl+K in the editor, open a
non-modal Popover anchored to the button instead of a modal Dialog. It
holds one plain-text URL field (URL keyboard, URL autocomplete, no
spellcheck, a placeholder) and Apply, Remove (when the selection is in a
link), and Cancel icon buttons with tooltips. Enter applies; Escape or
Cancel closes it and returns focus and the selection to the editor; a URL
that cannot be linked shows the field's error status and keeps focus in
the field.

The URL rules, hasNewTabLinks, promptForUrl, and the Cmd/Ctrl+K shortcut
are unchanged. RICHTEXT_ICON_KEYS gains applyLink, removeLink, and cancel
with bundled fallbacks, and the catalog gains the field's placeholder.

Co-authored-by: Emily Horsman <[email protected]>
…TextInput hints, and opens above the toolbar

- Apply and Cancel draw the shared check and close icons, so a theme
  restyles them through icons; Remove draws fixed artwork. The form adds
  no richtext:* icon key.
- The Popover's own focus handling moves focus to the URL field; the
  field's URL keyboard and spelling hints use TextInput's props.
- Cmd/Ctrl+K brings the Link button into view before the popover opens.
- The popover opens above the toolbar and flips below only when there is
  no room, so it does not cover the editor's first lines.
- A RichTextEditorToolbar record holds the link control's contract.
Resolves RichTextEditorToolbar.tsx (the link prop's doc keeps the popover
text and adds main's #9668 caret insertion) and RichTextEditor.test.tsx
(imports from both sides). The popover's apply path is main's single
update, which inserts the URL as link text at a collapsed caret.

Co-authored-by: ernestt <[email protected]>
…s the empty field and its placeholder

Apply and Cancel use the shared check and close icons and
RICHTEXT_ICON_KEYS is unchanged, so the changeset no longer claims new
icon keys. It also names the placement: above the toolbar, below only
without room.

Co-authored-by: ernestt <[email protected]>
…t the button's name; the record's compatibility row is present tense

Button on main no longer describes itself by a tooltip that repeats its
name, so tooltipOf falls back to the tooltip layer's text.

Co-authored-by: ernestt <[email protected]>
Behavior-neutral. The toolbar's link popover state and actions move to
useToolbarLink and ToolbarLinkPopover in ToolbarLinkPopover.tsx, with
isInsertLink. The URL form moves to linkForm.tsx as LinkForm, and the
address rule to linkEditing.ts as toLinkHref. The toolbar exports its
inline formats, their labels, the formats a selection carries, the
format command, and its glyph resolver for other RichText modules. The
package entry exports none of it.

Co-authored-by: Ernest Tien <[email protected]>
@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 13, 2026 12:44pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 11, 2026
@astracat-bot

astracat-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 13, 2026, 3:40 PM UTC

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for one small fix. The extraction itself keeps the package's API and the toolbar's behavior as they were.

Blocking

  • The new useEffect in useToolbarLink (packages/richtext/src/ToolbarLinkPopover.tsx:146) needs a short comment naming the external system it synchronizes (the Lexical editor's update and selection-change listeners), as architecture:react-component-runtime INV3 requires for a new Effect; pnpm review:pre reports the same line.

Non-blocking

  • The linkForm.tsx header says RichTextEditorLinkPopoverPlugin also renders this form, but that module is not on this branch yet, so describe only the toolbar's popover until it lands.

The /approve-spec comment covers spec records, and this pull request changes none, so it does not clear the fix above. The public surface is unchanged, the existing RichText tests pass without edits, and the link popover renders and behaves the same before and after in the insert, refused-address, edit and Cmd/Ctrl+K states.

Automated review (maintainer link)

Comment thread packages/richtext/src/linkForm.tsx Resolved
@cixzhang
cixzhang marked this pull request as ready for review November 11, 2026 08:52
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec f461a8d

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 11, 2026
cixzhang added a commit that referenced this pull request Nov 11, 2026
Takes #11189's RichTextEditorToolbar.tsx (the link popover moved to
ToolbarLinkPopover.tsx) and keeps this branch's linkEditing.ts, which
adds the plugin's link functions to #11189's toLinkHref.

Co-authored-by: ernestt <[email protected]>
cixzhang added a commit that referenced this pull request Nov 11, 2026
Takes #8718's shared link popover, URL form, and inline-format helpers (from #11189) in place of this branch's own extraction, and its useEditorFocusAndDrag in place of this toolbar's own focus and drag tracking. Table selections read their formats here, since the shared helper covers range and node selections.

Co-authored-by: Ernest Tien <[email protected]>
…ales

Button scales on press, so the open popover moved with a press on the
Link button it anchored to (layer-runtime INV22). It now anchors to a
wrapper around the button; Popover finds the button inside for its
handlers and ARIA.

Co-authored-by: ernestt <[email protected]>

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The new Effect in useToolbarLink now names the Lexical editor it synchronizes, which was the one blocking item, and the extraction keeps the package's public API and the toolbar's link behavior as they were.

Approved pending CI: the repository's pull-request CI has not run on this head, because it runs once the pull request targets main.

Non-blocking (still open from the earlier review)

  • The linkForm.tsx header (lines 10-12) still says RichTextEditorLinkPopoverPlugin renders this form, but that module is not on this branch yet.
  • The comment at ToolbarLinkPopover.tsx:122-124 is one 28-word sentence; two short sentences keep its reason.

Automated review (maintainer link)

Takes #8717's non-scaling wrapper around the toolbar's Link button: ToolbarLinkPopover anchors to that wrapper, and useToolbarLink's option, which scrolls the button into view, is now buttonRef.

Co-authored-by: Ernest Tien <[email protected]>
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 919de0c

cixzhang added a commit that referenced this pull request Nov 11, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The extraction keeps @astryxdesign/richtext's public API and the toolbar's link behavior as they were, including the base branch's anchor fix that this head merges.

Approved pending CI: the repository's pull-request CI has not run on this head; it runs once the pull request targets main.

Non-blocking

  • The linkForm.tsx header (lines 10-12) says RichTextEditorLinkPopoverPlugin renders this form, but that module is not on this branch yet.
  • The comment at ToolbarLinkPopover.tsx:122-124 is one 28-word sentence; two short sentences keep its reason.
  • The description's Change section names the hook's option anchorRef; useToolbarLink now takes buttonRef, and anchorRef belongs to ToolbarLinkPopover.

Automated review (maintainer link)

cixzhang and others added 3 commits November 11, 2026 06:18
Brings in #11177 (Popover focus entry in document order).

Co-authored-by: ernestt <[email protected]>
With Popover's focus entry taking the first content control in document
order (#11177), the form no longer turns hasAutoFocus off and focuses
its field from an Effect. The record drops FR4's slot-system status
line and says AST-061 owns the toolbar's props; the link anchor styles
no longer split the Divider comment from its styles.

Co-authored-by: ernestt <[email protected]>
Takes #8717's removal of the form's focus Effect and of hasAutoFocus={false}: Popover's focus entry focuses the URL field. In this branch that code lives in linkForm.tsx and ToolbarLinkPopover.tsx.

Co-authored-by: Ernest Tien <[email protected]>

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The extraction keeps @astryxdesign/richtext's public API and the toolbar's link behavior as they were, and the merge carries the base branch's focus fix (Popover's focus entry focuses the URL field) into the moved form and popover.

Approved pending CI: the repository's pull-request CI has not run on this head; it runs once the pull request targets main.

Non-blocking

  • The linkForm.tsx header (lines 10-12) says RichTextEditorLinkPopoverPlugin renders this form, but that module is not on this branch yet.
  • The comment at ToolbarLinkPopover.tsx:122-124 is one 28-word sentence; two short sentences keep its reason.
  • The description's Change section names the hook's option anchorRef; useToolbarLink takes buttonRef, and anchorRef belongs to ToolbarLinkPopover.

Automated review (maintainer link)

cixzhang added a commit that referenced this pull request Nov 11, 2026
…ge) into richtext-link-card

LinkForm no longer focuses its field from an Effect, since the toolbar's
Popover focuses it. The plugin's popover is no Popover, so LinkForm gains
hasAutoFocus (TextInput's own) and the plugin's Edit view sets it.

Co-authored-by: ernestt <[email protected]>
@cixzhang
cixzhang marked this pull request as draft November 13, 2026 12:00
@cixzhang
cixzhang changed the base branch from richtext-link-popover to main November 13, 2026 12:00
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a000f61

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 4e79d9b

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
richtext/RichTextEditorToolbar 298.2 kB (+414 B) · 454 B CSS (0) 671 (−297) — · ✓ · ✓

Package size: @astryxdesign/richtext 239.9 kB packed (+6.0 kB); no new dependencies.

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes for one record link and two description fixes; the code itself needs no change. The extraction keeps @astryxdesign/richtext's public API and the toolbar's link behavior unchanged, and every RichText test passes.

Blocking

  • Miss: ToolbarLinkPopover.tsx and linkForm.tsx now hold the link popover that component:RichTextEditorToolbar governs, but nothing links them to that record (pnpm specs:for on either file lists no component record), so add a path-applicability:v1 block naming both files to docs/specs/components/RichTextEditorToolbar/RichTextEditorToolbar.spec.md, as knowledge-contracts INV26 requires.
  • Newly live check: the Change section says useToolbarLink takes {anchorRef, hasNewTabLinks, promptForUrl}, but it takes buttonRef (packages/richtext/src/ToolbarLinkPopover.tsx:98-109); anchorRef belongs to ToolbarLinkPopover.
  • Regression: #8717 has merged and this pull request now targets main, so the description's note that it is stacked on #8717 no longer holds, and its Evidence and Testing sections report 47 files and 765 RichText tests where this head runs 48 files and 783 tests.

Non-blocking

  • The linkForm.tsx header (lines 10-12) says RichTextEditorLinkPopoverPlugin renders this form, but that module is not in the repository yet.
  • The comment at ToolbarLinkPopover.tsx:122-124 is one 28-word sentence; two short sentences keep its reason.
  • The RichTextEditorToolbar.tsx header grows by three lines to list internal helpers; one line keeps it from growing.
Claims and files checked
  • Changeset: an internal move with no change for apps. Verified: no public API row changes, and the link states are identical before and after.
  • The pull request is stacked on #8717 and retargets once that lands. False: #8717 has merged, and this pull request targets main.
  • #8718 and #8722 build on this work. Consistent: both are open, and #8722 says it sits on this pull request.
  • The link editing and format helpers were private to the toolbar. Verified at the base.
  • The toolbar behaves exactly as before (buttons, labels, pressed states, Cmd/Ctrl+K, placement, form, focus return, refused address, promptForUrl). Verified: identical frames and ARIA and focus probes in four states, the link tests pass unedited, and the promptForUrl branch moved verbatim (ToolbarLinkPopover.tsx:231-244).
  • The package entry exports nothing new. Verified: index.ts is unchanged, and the built surface has no changes.
  • The change is a move with no logic change. Verified: readLinkContext reuses the new selection note, and one type cast is dropped.
  • useToolbarLink takes anchorRef. False: it takes buttonRef (ToolbarLinkPopover.tsx:98-109).
  • ToolbarLinkPopover is the non-modal popover on the Link button, and isInsertLink is the Cmd/Ctrl+K test. Verified (ToolbarLinkPopover.tsx:345-393, :54-56).
  • LinkForm moved as-is, with the Remove glyph. Verified: the code is identical; only its name and comments changed.
  • toLinkHref is the sanitize-or-refuse rule that Apply used inline. Verified (linkEditing.ts:17-20).
  • The toolbar exports seven helpers and uses them itself. Verified (RichTextEditorToolbar.tsx:200-253, :457, :476).
  • The code was first written for #8722 and ported here. This cannot be checked from the code; it is consistent with #8722.
  • Every RichText test passes unchanged, 47 files and 765 tests. The tests pass and the existing ones are unedited, but the counts are false: 48 files and 783 tests at this head.
  • A new test covers toLinkHref. Verified (2 tests).
  • No CI, public API, behavior, visual or policy change, and no internal context. Verified.
  • ESLint, Prettier and the repository checks pass. Verified: 0 ESLint errors on the changed files, Prettier clean, and every repository check that runs without git passes.
  • Files: .changeset/richtext-link-popover-extraction.md clear; RichTextEditorToolbar.tsx clear apart from the header note; ToolbarLinkPopover.tsx and linkForm.tsx not reached by their record (blocking above), plus the comment and header notes; linkEditing.ts clear; linkEditing.test.ts clear.

Automated review (maintainer link)

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 13, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 4e79d9b

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 13, 2026

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: the required checks are still running on this head.

The extraction keeps @astryxdesign/richtext's public API and the toolbar's link behavior as they were: the built package surface is unchanged, the existing link and public-surface tests pass without edits, and the link popover's insert, refused-address, edit, Cmd/Ctrl+K and no-room-above states render identically before and after. The record's new path list routes both new popover files to the toolbar's record. No changes are needed from you.

Claims and files checked
  • Claim (changeset): the link popover, its URL form, the address rule and the inline-format helpers move into internal modules — verified: ToolbarLinkPopover.tsx, linkForm.tsx, linkEditing.ts, and the helpers exported from RichTextEditorToolbar.tsx:199-253 and :475.
  • Claim (changeset): apps see no change, as a patch — verified: 0 public API rows, identical captures, and the changeset check passes.
  • Claim: follows the toolbar link popover change, which is on main — verified.
  • Claim: the toolbar behaves exactly as before (buttons, labels, pressed states, Cmd/Ctrl+K, placement, form, focus return, refused-address error, promptForUrl) — verified: unedited RichTextEditorToolbarLink.test.tsx passes; frames and accessibility probes match.
  • Claim: the package entry exports nothing new — verified: index.ts unchanged, publicSurface.test.ts passes.
  • Claim: a move with no logic change — verified: the selection memory now registers its own editor listeners in useToolbarLink with the same logic.
  • Claim: the new modules hold useToolbarLink(editor, {buttonRef, hasNewTabLinks, promptForUrl}), ToolbarLinkPopover, isInsertLink, LinkForm, REMOVE_LINK_GLYPH and toLinkHref — verified.
  • Claim: the record's path list lets the spec lookup find the record for both popover files — verified.
  • Claim: the toolbar exports seven helpers and uses each itself — verified.
  • Claim: 48 test files and 783 tests pass, with the link and public-surface tests unchanged and a new toLinkHref test — verified.
  • Claim: lint, formatting and repository checks pass, with no CI impact — verified: ESLint 0 errors, Prettier clean, changeset and knowledge checks pass, no CI file changed.
  • Files: .changeset/richtext-link-popover-extraction.md, RichTextEditorToolbar.spec.md, RichTextEditorToolbar.tsx, ToolbarLinkPopover.tsx, linkEditing.ts, linkEditing.test.ts, linkForm.tsx — each clear.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 13, 2026 15:13
@cixzhang
cixzhang merged commit 5c44304 into main Nov 13, 2026
131 checks passed
@cixzhang
cixzhang deleted the richtext-link-extraction branch November 13, 2026 16:00
cixzhang added a commit that referenced this pull request Nov 14, 2026
Retargets the link popover plugin onto main after its parents (#8717, #11189) merged as squashes. The branch keeps only its own changes over the parents' merged state: the plugin, its record, story, tests and Chromium spec; the shared reposition scheduler and the focus-and-drag hook; and their uses in the task-checkbox and code-block header plugins, which main moved under internal/. The parents' copies of their own files and changesets give way to main's.

Main's React lint rules now cover the plugin: its click and focus listeners attach through module functions that return their own cleanup, and the popover's layout-measured place keeps its set in a layout effect with a reason.

This branch was successfully deployed

1 active deployment
Preview — 4e79d9b9 Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants