Skip to content

feat(lab): add link support to RichTextEditor - #4670

Merged
potatowagon merged 1 commit into
meta:mainfrom
potatowagon:navi/feat/richtext-links
Aug 4, 2026
Merged

potatowagon merged 1 commit into
meta:mainfrom
potatowagon:navi/feat/richtext-links

Conversation

@potatowagon

@potatowagon potatowagon commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds link support to the experimental RichTextEditor (@astryxdesign/lab). Previously LinkNode/AutoLinkNode + LinkPlugin were registered, so links rendered — but there was no way to create one. This adds creation, auto-linking, and new-tab behavior.

Why this shape — EPS eps-lexical compatibility

The end goal is to back Meta's EPS EPSRichTextArea (nest/libs/eps-lexical) with this editor. So the design deliberately matches EPS's command + node contract, not its UI chrome:

  • Link toggle bottoms out on Lexical's TOGGLE_LINK_COMMAND (same as eps-lexical's LinkPopoverPlugin.handleSubmit)
  • Active state syncs via $isLinkNode(parent) || $isLinkNode(node) (identical to the EPS toolbar)
  • Collapsed-caret fallback inserts a $createLinkNode (matches EPS)
  • Auto-link uses the matcher shape (createLinkMatcherWithRegExp + attributes) and new-tab defaults — EPS can pass its own richer matchers (e.g. D123/T456/S789 intern URLs)
  • New-tab is baked into the link node data (target/rel via the TOGGLE_LINK_COMMAND {url, target, rel} payload) so it serializes and round-trips — no DOM-patching plugin

EPS keeps its own popover UI / hardened auto-link fork; astryx stays OSS-minimal and exposes the extension points (promptForUrl, matchers, linkOpensInNewTab) so EPS drops in without changing the contract.

Changes

  • RichTextEditorToolbar: Link button (on by default; hasLink={false} to hide) + Cmd/Ctrl+K (via Lexical's isExactShortcutMatch, mirroring the playground's ShortcutsPlugin). Prompts for a URL via overridable promptForUrl (default window.prompt), sanitizes it, toggles the link. Themeable icon via the richtext:link registry key.
  • New-tab baked into node data: created links carry target="_blank" + rel="noopener noreferrer" by default; linkOpensInNewTab={false} opts out.
  • RichTextEditorAutoLinkPlugin: auto-linkify typed/pasted URLs + emails (new-tab); matchers overridable.
  • linkUtils: sanitizeUrl / validateUrl (only http/https/mailto/tel; rejects javascript:/data:) + URL_MATCHER / EMAIL_MATCHER.
  • Tests, Storybook stories (WithLinks, WithAutoLink), doc updates.

Testing

  • pnpm -F @astryxdesign/lab typecheck — clean (pre-existing .doc.mjs implicit-any warnings unrelated)
  • RichTextEditor.test.tsx — passing (incl. new link/sanitizer/autolink/new-tab/shortcut tests)
  • check:sync / check:package-boundaries / check:changesets — clean

@vercel

vercel Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 3, 2026 6:17am

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 3, 2026
@potatowagon
potatowagon force-pushed the navi/feat/richtext-links branch from 91a0f25 to 4149440 Compare August 3, 2026 05:47
Add link creation/editing to the experimental RichTextEditor, matching
the command + node contract of Meta's EPS eps-lexical editor so its
internals can later be backed by this component.

- RichTextEditorToolbar: Link button + Cmd/Ctrl+K toggle a link on the
  selection via Lexical TOGGLE_LINK_COMMAND; active state synced with
  $isLinkNode(parent) || $isLinkNode(node). URL obtained via an
  overridable promptForUrl (window.prompt default), sanitized to
  http/https/mailto/tel. Collapsed-caret fallback inserts a link node.
- New-tab is baked into the link node data (target=_blank + rel via the
  TOGGLE_LINK_COMMAND {url, target, rel} payload), so it serializes and
  round-trips — no DOM-patching plugin. Toggle with linkOpensInNewTab.
- RichTextEditorAutoLinkPlugin: auto-linkify typed/pasted URLs + emails
  with new-tab attributes; matchers overridable.
- linkUtils: sanitizeUrl/validateUrl + URL/EMAIL matchers.
- Tests, storybook stories, docs.
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

RichTextEditor (@astryxdesign/lab) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 1491 -
Complexity N/A Very High (96) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/lab N/A 3.5KB 1.5KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 3, 2026
@potatowagon
potatowagon merged commit 0d8d5ba into meta:main Aug 4, 2026
20 of 21 checks passed
cixzhang added a commit that referenced this pull request Aug 12, 2026
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
cixzhang added a commit that referenced this pull request Aug 12, 2026
`With Links` and `With Auto Link` arrived with link support in #4670, which
touched no `packages/core/src` component, so `check-components` skipped
pr-a11y and the two stories were never added to the baseline. They violate
`aria-input-field-name` for exactly the reason the twelve baselined sibling
stories do: the contenteditable carries `aria-labelledby` pointing at the
control's own id, which no element in the DOM has, so the editor has no
accessible name.

Measured: an audit of unmodified origin/main reports the identical fifteen
violations, including these two, so this is pre-existing debt this PR only
surfaces (pr-a11y audits the stories of the components a PR touches). Fixing
the accessible name properly is a component-level change that would resolve
all fourteen stories and retire the twelve existing entries — out of scope
for a theme-class fix.

@cixzhang
cixzhang added a commit that referenced this pull request Aug 12, 2026
… scope

pr-a11y audits the components a PR touches. This PR touches only
`*.doc.mjs` metadata for these components — Storybook never reads
`.doc.mjs` — so it renders nothing differently; it just widens the
audit's scope onto violations that were already there.

Each entry was verified by auditing the story at unmodified
`origin/main` and reproducing it:

- `RichTextEditor::With Links` / `With Auto Link` —
  `aria-input-field-name`. The Lexical `role="textbox"` host has no
  accessible name in ALL 14 RichTextEditor stories; twelve of them are
  already baselined. These two arrived with link support (#4670,
  2026-08-04) after the baseline snapshot was generated (2026-07-31),
  which is the only reason they are missing.
- `Schedule::List` — `color-contrast`. Schedule's stories anchor their
  events to `new Date()`, and past events render dimmed (#a9a9a9 on
  #ffffff, 2.35:1). Whether a given view contains a past event depends
  on the wall-clock time of the run, so the violation moves between
  stories: with the clock pinned to the failing CI run's date it
  reproduces on `List` at unmodified main; pinned to today it does not.
  Its five sibling Schedule stories are already baselined for the same
  rule.
- `ListInput::*` (5 stories) — `aria-allowed-attr`. ListInput puts
  `aria-required` on a `role="group"` element, which does not support
  it. ListInput landed (#4740) after the baseline snapshot and has
  never been gated. NEEDS A REAL FIX in its own PR: Slider and
  FileInput already work around the same restriction (see the comments
  at Slider.tsx:452 and FileInput.tsx:472), and picking between those
  remedies is a call for ListInput's owner, not this chore.

Hand-added rather than regenerated: `pnpm a11y:baseline` rewrites every
entry for the components it audits, which would have dropped the
Schedule, LogStream and Chat contrast entries that happen not to
reproduce on this machine today.

@cixzhang
cixzhang added a commit that referenced this pull request Aug 12, 2026
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
cixzhang added a commit that referenced this pull request Aug 12, 2026
`With Links` and `With Auto Link` arrived with link support in #4670, which
touched no `packages/core/src` component, so `check-components` skipped
pr-a11y and the two stories were never added to the baseline. They violate
`aria-input-field-name` for exactly the reason the twelve baselined sibling
stories do: the contenteditable carries `aria-labelledby` pointing at the
control's own id, which no element in the DOM has, so the editor has no
accessible name.

Measured: an audit of unmodified origin/main reports the identical fifteen
violations, including these two, so this is pre-existing debt this PR only
surfaces (pr-a11y audits the stories of the components a PR touches). Fixing
the accessible name properly is a component-level change that would resolve
all fourteen stories and retire the twelve existing entries — out of scope
for a theme-class fix.

@cixzhang
cixzhang added a commit that referenced this pull request Aug 12, 2026
… scope

pr-a11y audits the components a PR touches. This PR touches only
`*.doc.mjs` metadata for these components — Storybook never reads
`.doc.mjs` — so it renders nothing differently; it just widens the
audit's scope onto violations that were already there.

Each entry was verified by auditing the story at unmodified
`origin/main` and reproducing it:

- `RichTextEditor::With Links` / `With Auto Link` —
  `aria-input-field-name`. The Lexical `role="textbox"` host has no
  accessible name in ALL 14 RichTextEditor stories; twelve of them are
  already baselined. These two arrived with link support (#4670,
  2026-08-04) after the baseline snapshot was generated (2026-07-31),
  which is the only reason they are missing.
- `Schedule::List` — `color-contrast`. Schedule's stories anchor their
  events to `new Date()`, and past events render dimmed (#a9a9a9 on
  #ffffff, 2.35:1). Whether a given view contains a past event depends
  on the wall-clock time of the run, so the violation moves between
  stories: with the clock pinned to the failing CI run's date it
  reproduces on `List` at unmodified main; pinned to today it does not.
  Its five sibling Schedule stories are already baselined for the same
  rule.
- `ListInput::*` (5 stories) — `aria-allowed-attr`. ListInput puts
  `aria-required` on a `role="group"` element, which does not support
  it. ListInput landed (#4740) after the baseline snapshot and has
  never been gated. NEEDS A REAL FIX in its own PR: Slider and
  FileInput already work around the same restriction (see the comments
  at Slider.tsx:452 and FileInput.tsx:472), and picking between those
  remedies is a call for ListInput's owner, not this chore.

Hand-added rather than regenerated: `pnpm a11y:baseline` rewrites every
entry for the components it audits, which would have dropped the
Schedule, LogStream and Chat contrast entries that happen not to
reproduce on this machine today.

@cixzhang
cixzhang added a commit that referenced this pull request Aug 14, 2026
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
cixzhang added a commit that referenced this pull request Aug 14, 2026
`With Links` and `With Auto Link` arrived with link support in #4670, which
touched no `packages/core/src` component, so `check-components` skipped
pr-a11y and the two stories were never added to the baseline. They violate
`aria-input-field-name` for exactly the reason the twelve baselined sibling
stories do: the contenteditable carries `aria-labelledby` pointing at the
control's own id, which no element in the DOM has, so the editor has no
accessible name.

Measured: an audit of unmodified origin/main reports the identical fifteen
violations, including these two, so this is pre-existing debt this PR only
surfaces (pr-a11y audits the stories of the components a PR touches). Fixing
the accessible name properly is a component-level change that would resolve
all fourteen stories and retire the twelve existing entries — out of scope
for a theme-class fix.

@cixzhang
cixzhang added a commit that referenced this pull request Aug 14, 2026
… scope

pr-a11y audits the components a PR touches. This PR touches only
`*.doc.mjs` metadata for these components — Storybook never reads
`.doc.mjs` — so it renders nothing differently; it just widens the
audit's scope onto violations that were already there.

Each entry was verified by auditing the story at unmodified
`origin/main` and reproducing it:

- `RichTextEditor::With Links` / `With Auto Link` —
  `aria-input-field-name`. The Lexical `role="textbox"` host has no
  accessible name in ALL 14 RichTextEditor stories; twelve of them are
  already baselined. These two arrived with link support (#4670,
  2026-08-04) after the baseline snapshot was generated (2026-07-31),
  which is the only reason they are missing.
- `Schedule::List` — `color-contrast`. Schedule's stories anchor their
  events to `new Date()`, and past events render dimmed (#a9a9a9 on
  #ffffff, 2.35:1). Whether a given view contains a past event depends
  on the wall-clock time of the run, so the violation moves between
  stories: with the clock pinned to the failing CI run's date it
  reproduces on `List` at unmodified main; pinned to today it does not.
  Its five sibling Schedule stories are already baselined for the same
  rule.
- `ListInput::*` (5 stories) — `aria-allowed-attr`. ListInput puts
  `aria-required` on a `role="group"` element, which does not support
  it. ListInput landed (#4740) after the baseline snapshot and has
  never been gated. NEEDS A REAL FIX in its own PR: Slider and
  FileInput already work around the same restriction (see the comments
  at Slider.tsx:452 and FileInput.tsx:472), and picking between those
  remedies is a call for ListInput's owner, not this chore.

Hand-added rather than regenerated: `pnpm a11y:baseline` rewrites every
entry for the components it audits, which would have dropped the
Schedule, LogStream and Chat contrast entries that happen not to
reproduce on this machine today.

@cixzhang
cixzhang added a commit that referenced this pull request Aug 14, 2026
… scope

pr-a11y audits the components a PR touches. This PR touches only
`*.doc.mjs` metadata for these components — Storybook never reads
`.doc.mjs` — so it renders nothing differently; it just widens the
audit's scope onto violations that were already there.

Each entry was verified by auditing the story at unmodified
`origin/main` and reproducing it:

- `RichTextEditor::With Links` / `With Auto Link` —
  `aria-input-field-name`. The Lexical `role="textbox"` host has no
  accessible name in ALL 14 RichTextEditor stories; twelve of them are
  already baselined. These two arrived with link support (#4670,
  2026-08-04) after the baseline snapshot was generated (2026-07-31),
  which is the only reason they are missing.
- `Schedule::List` — `color-contrast`. Schedule's stories anchor their
  events to `new Date()`, and past events render dimmed (#a9a9a9 on
  #ffffff, 2.35:1). Whether a given view contains a past event depends
  on the wall-clock time of the run, so the violation moves between
  stories: with the clock pinned to the failing CI run's date it
  reproduces on `List` at unmodified main; pinned to today it does not.
  Its five sibling Schedule stories are already baselined for the same
  rule.
- `ListInput::*` (5 stories) — `aria-allowed-attr`. ListInput puts
  `aria-required` on a `role="group"` element, which does not support
  it. ListInput landed (#4740) after the baseline snapshot and has
  never been gated. NEEDS A REAL FIX in its own PR: Slider and
  FileInput already work around the same restriction (see the comments
  at Slider.tsx:452 and FileInput.tsx:472), and picking between those
  remedies is a call for ListInput's owner, not this chore.

Hand-added rather than regenerated: `pnpm a11y:baseline` rewrites every
entry for the components it audits, which would have dropped the
Schedule, LogStream and Chat contrast entries that happen not to
reproduce on this machine today.

@cixzhang
cixzhang added a commit that referenced this pull request Aug 25, 2026
… scope

pr-a11y audits the components a PR touches. This PR touches only
`*.doc.mjs` metadata for these components — Storybook never reads
`.doc.mjs` — so it renders nothing differently; it just widens the
audit's scope onto violations that were already there.

Each entry was verified by auditing the story at unmodified
`origin/main` and reproducing it:

- `RichTextEditor::With Links` / `With Auto Link` —
  `aria-input-field-name`. The Lexical `role="textbox"` host has no
  accessible name in ALL 14 RichTextEditor stories; twelve of them are
  already baselined. These two arrived with link support (#4670,
  2026-08-04) after the baseline snapshot was generated (2026-07-31),
  which is the only reason they are missing.
- `Schedule::List` — `color-contrast`. Schedule's stories anchor their
  events to `new Date()`, and past events render dimmed (#a9a9a9 on
  #ffffff, 2.35:1). Whether a given view contains a past event depends
  on the wall-clock time of the run, so the violation moves between
  stories: with the clock pinned to the failing CI run's date it
  reproduces on `List` at unmodified main; pinned to today it does not.
  Its five sibling Schedule stories are already baselined for the same
  rule.
- `ListInput::*` (5 stories) — `aria-allowed-attr`. ListInput puts
  `aria-required` on a `role="group"` element, which does not support
  it. ListInput landed (#4740) after the baseline snapshot and has
  never been gated. NEEDS A REAL FIX in its own PR: Slider and
  FileInput already work around the same restriction (see the comments
  at Slider.tsx:452 and FileInput.tsx:472), and picking between those
  remedies is a call for ListInput's owner, not this chore.

Hand-added rather than regenerated: `pnpm a11y:baseline` rewrites every
entry for the components it audits, which would have dropped the
Schedule, LogStream and Chat contrast entries that happen not to
reproduce on this machine today.

@cixzhang

This branch was successfully deployed

1 active deployment
Preview — 1fda690f Deployed Aug 3, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants