Repository navigation
refactor(richtext): share the toolbar's link popover and format helpers - #11189
Conversation
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.
…llIntoView does not stop the popover
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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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
useEffectinuseToolbarLink(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), asarchitecture:react-component-runtimeINV3 requires for a new Effect;pnpm review:prereports the same line.
Non-blocking
- The
linkForm.tsxheader saysRichTextEditorLinkPopoverPluginalso 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.
|
/approve-spec f461a8d |
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]>
Co-authored-by: Ernest Tien <[email protected]>
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]>
There was a problem hiding this comment.
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.tsxheader (lines 10-12) still saysRichTextEditorLinkPopoverPluginrenders this form, but that module is not on this branch yet. - The comment at
ToolbarLinkPopover.tsx:122-124is one 28-word sentence; two short sentences keep its reason.
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]>
|
/approve-spec 919de0c |
…into richtext-link-card Co-authored-by: ernestt <[email protected]>
There was a problem hiding this comment.
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.tsxheader (lines 10-12) saysRichTextEditorLinkPopoverPluginrenders this form, but that module is not on this branch yet. - The comment at
ToolbarLinkPopover.tsx:122-124is one 28-word sentence; two short sentences keep its reason. - The description's Change section names the hook's option
anchorRef;useToolbarLinknow takesbuttonRef, andanchorRefbelongs toToolbarLinkPopover.
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]>
There was a problem hiding this comment.
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.tsxheader (lines 10-12) saysRichTextEditorLinkPopoverPluginrenders this form, but that module is not on this branch yet. - The comment at
ToolbarLinkPopover.tsx:122-124is one 28-word sentence; two short sentences keep its reason. - The description's Change section names the hook's option
anchorRef;useToolbarLinktakesbuttonRef, andanchorRefbelongs toToolbarLinkPopover.
…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]>
|
/approve-spec a000f61 |
PR Analysis Report🔎 Preview ·
|
| 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
There was a problem hiding this comment.
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.tsxandlinkForm.tsxnow hold the link popover thatcomponent:RichTextEditorToolbargoverns, but nothing links them to that record (pnpm specs:foron either file lists no component record), so add apath-applicability:v1block naming both files todocs/specs/components/RichTextEditorToolbar/RichTextEditorToolbar.spec.md, asknowledge-contractsINV26 requires. - Newly live check: the Change section says
useToolbarLinktakes{anchorRef, hasNewTabLinks, promptForUrl}, but it takesbuttonRef(packages/richtext/src/ToolbarLinkPopover.tsx:98-109);anchorRefbelongs toToolbarLinkPopover. - 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.tsxheader (lines 10-12) saysRichTextEditorLinkPopoverPluginrenders this form, but that module is not in the repository yet. - The comment at
ToolbarLinkPopover.tsx:122-124is one 28-word sentence; two short sentences keep its reason. - The
RichTextEditorToolbar.tsxheader 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 thepromptForUrlbranch moved verbatim (ToolbarLinkPopover.tsx:231-244). - The package entry exports nothing new. Verified:
index.tsis unchanged, and the built surface has no changes. - The change is a move with no logic change. Verified:
readLinkContextreuses the new selection note, and one type cast is dropped. useToolbarLinktakesanchorRef. False: it takesbuttonRef(ToolbarLinkPopover.tsx:98-109).ToolbarLinkPopoveris the non-modal popover on the Link button, andisInsertLinkis the Cmd/Ctrl+K test. Verified (ToolbarLinkPopover.tsx:345-393,:54-56).LinkFormmoved as-is, with the Remove glyph. Verified: the code is identical; only its name and comments changed.toLinkHrefis 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.mdclear;RichTextEditorToolbar.tsxclear apart from the header note;ToolbarLinkPopover.tsxandlinkForm.tsxnot reached by their record (blocking above), plus the comment and header notes;linkEditing.tsclear;linkEditing.test.tsclear.
…s; comments tighten
|
/approve-spec 4e79d9b |
There was a problem hiding this comment.
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 fromRichTextEditorToolbar.tsx:199-253and: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: uneditedRichTextEditorToolbarLink.test.tsxpasses; frames and accessibility probes match. - Claim: the package entry exports nothing new — verified:
index.tsunchanged,publicSurface.test.tspasses. - Claim: a move with no logic change — verified: the selection memory now registers its own editor listeners in
useToolbarLinkwith the same logic. - Claim: the new modules hold
useToolbarLink(editor, {buttonRef, hasNewTabLinks, promptForUrl}),ToolbarLinkPopover,isInsertLink,LinkForm,REMOVE_LINK_GLYPHandtoLinkHref— 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
toLinkHreftest — 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.
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.
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
RichTextEditorToolbarbehaves exactly as it does onmainafter #8717: the same buttons, labels, pressed states, Cmd/Ctrl+K, link popover placement, form, focus return, refused-address error, andpromptForUrlpath. 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; andisInsertLink, the Cmd/Ctrl+K test.linkForm.tsx:LinkForm(the toolbar's URL form, moved as-is) andREMOVE_LINK_GLYPH.linkEditing.ts:toLinkHref(entered), the sanitize-or-refuse rule the toolbar's Apply used inline.component:RichTextEditorToolbarnamesToolbarLinkPopover.tsxandlinkForm.tsxin apath-applicability:v1block, sopnpm specs:forfinds the record for both.RichTextEditorToolbar.tsxexportsINLINE_FORMAT_ACTIONS,InlineFormat,inlineFormatLabels,$inlineFormatsOf,formatSelection,ToolbarIconNameanduseToolbarIconfor other RichText modules, and uses them itself.Originally written by @ernestt as part of #8722; ported onto #8717, now on
main.Evidence
promptForUrl) run without edits. A newlinkEditing.test.tscoverstoLinkHref.Scope
Components: RichTextEditorToolbar
Testing
pnpm exec vitest run packages/richtext/: 48 files, 783 tests pass.pnpm check:repo) pass.