Skip to content

DataViews: Back richtext control with a @wordpress/components shell (alt to #78471) - #79345

Merged
adamsilverstein merged 11 commits into
move/rich-text-control-packagefrom
try/rich-text-shell-in-components
Jul 6, 2026
Merged

adamsilverstein merged 11 commits into
move/rich-text-control-packagefrom
try/rich-text-shell-in-components

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Jun 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Stacked on #78471. This implements the counter-proposal raised in #78471 review by @ciampo and @mirka: instead of a dedicated @wordpress/rich-text-control package that hard-wires @wordpress/rich-text, host a presentational shell in @wordpress/components and inject the rich-text wiring from the consumer.

Because it is stacked on #78471, the diff reads as "convert approach A → B". If we land this direction, the two collapse into a single PR off trunk.

Note

The branch was rebuilt linearly on the current base tip on 2026-07-05. This removed the unrelated collaboration/autosave changes that had leaked into the diff (they were artifacts of a criss-cross merge topology, flagged by @ntsekouras and @talldan), and carried over everything the base gained since the original spike: the TypeScript conversion, Enter/line-break handling, the popover focus-out tracking, the placeholder styles, and the DataForm Storybook story.

What changed (delta vs #78471)

@wordpress/rich-text gains private event-listener helpers

  • Per @ntsekouras's suggestion, the keydown/input dispatch helpers now live next to the keyboardShortcutContext / inputEventContext they serve, exposed as private APIs (shortcutsListener, inputEventsListener). Consumers no longer duplicate this glue.

@wordpress/components gains a private, presentational RichTextControl

  • Owns only the chrome: BaseControl + label, the contentEditable element, and the Popover.Slot scaffolding plus the blur/focus selection heuristic (including the document-level focus tracking that deselects the field once focus leaves a popover it opened).
  • Zero @wordpress/rich-text dependency. The editable behavior (value, formatting, keyboard shortcuts) is injected by the consumer through editableRef and children; selection is controlled via onSelectedChange.
  • Exposed as a private API for now (the public-vs-private and @wordpress/ui-future questions stay out of scope).

@wordpress/dataviews owns the rich-text "assembly"

  • The richtext DataForm control becomes the assembly: it calls useRichText, wires FormatEdit, the event listeners (from @wordpress/rich-text), Enter/line-break handling, and format input rules, and renders the components shell.
  • Written in TypeScript (per @andrewserong) — no more @ts-nocheck vendoring.
  • The DataForm "Layout Regular" story exercises the control end to end in Storybook.

@wordpress/rich-text-control is removed.

Why this shape

The ref-cycle that makes a "clean" split look hard (useRichText produces the ref the shell needs, but isSelected feeds back into useRichText) resolves by making the shell a controlled component: the assembly owns isSelected, the shell drives the focus/blur transitions via onSelectedChange. Standard React data flow; state lives in the assembly, DOM heuristics live in the shell.

Net effect: @wordpress/components gains a reusable presentational primitive, @wordpress/rich-text stays small and now hosts the shared dispatch glue, dataviews owns the wiring, and there is no standalone package. This also fully resolves the bundled-package/private-API concern from #78471 review: nothing outside the monorepo can end up bundling a mismatched copy of a @wordpress/rich-text-control npm package, because there isn't one.

Test coverage

Coverage is preserved and split along the new boundary:

  • Components (rich-text-control/test): presentational shell — label/aria, id, className merge, focus-on-mount, editableRef attachment, and the controlled-selection / popover-slot blur heuristic including the popover-exit focus tracking (14 tests).
  • DataViews (richtext/test/control.js): the integration suite relocated from the package — Enter/line-break behavior, keyboard shortcuts, popover focus excursions, and format input rules end-to-end through the assembly + shell (20 tests).
  • DataViews (dataform-controls/test/richtext.tsx): prop wiring (5 tests).

Verified locally: all three suites green (39 tests), plus the full @wordpress/rich-text (218) and @wordpress/dataviews (290) suites; ESLint clean on all changed files.

Testing

Test the rich text component as part the Notes feature - add a note, then use keyboard shortcuts to add bold or italic and backticks to add code formatting, command k to add a link. https://playground.wordpress.net/?gutenberg-pr=78242 (code #78242)

@github-actions github-actions Bot added [Package] Components /packages/components [Package] Private APIs /packages/private-apis [Package] DataViews /packages/dataviews labels Jun 19, 2026
@adamsilverstein
adamsilverstein requested review from ciampo and mirka June 19, 2026 09:52
@adamsilverstein adamsilverstein self-assigned this Jun 19, 2026
@adamsilverstein adamsilverstein added [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Feature New feature to highlight in changelogs. and removed [Type] Enhancement A suggestion for improvement. labels Jun 19, 2026
@github-actions

github-actions Bot commented Jun 19, 2026 •

Copy link
Copy Markdown

Size Change: -1.95 kB (-0.03%)

Total Size: 7.64 MB

📦 View Changed
Filename Size Change
build/modules/content-types/index.min.js 161 kB -604 B (-0.37%)
build/scripts/block-editor/index.min.js 386 kB -563 B (-0.15%)
build/scripts/components/index.min.js 267 kB +475 B (+0.18%)
build/scripts/edit-site/index.min.js 299 kB -614 B (-0.21%)
build/scripts/editor/index.min.js 491 kB -595 B (-0.12%)
build/scripts/media-utils/index.min.js 116 kB -542 B (-0.47%)
build/scripts/private-apis/index.min.js 1.13 kB -7 B (-0.61%)
build/scripts/rich-text/index.min.js 14.5 kB +83 B (+0.58%)
build/styles/components/style-rtl.css 18.2 kB +107 B (+0.59%)
build/styles/components/style-rtl.min.css 15.1 kB +102 B (+0.68%)
build/styles/components/style.css 18.3 kB +108 B (+0.59%)
build/styles/components/style.min.css 15.1 kB +102 B (+0.68%)

compressed-size-action

@github-actions github-actions Bot added [Package] Element /packages/element [Package] Date /packages/date [Package] Data /packages/data [Package] Server Side Render /packages/server-side-render [Package] A11y /packages/a11y [Package] Autop /packages/autop [Package] DOM ready /packages/dom-ready [Package] Hooks /packages/hooks [Package] i18n /packages/i18n [Package] is-shallow-equal /packages/is-shallow-equal [Package] Url /packages/url [Package] Word count /packages/wordcount [Package] Deprecated packages/deprecated [Package] Blob /packages/blob [Package] Compose /packages/compose [Package] Core data /packages/core-data [Package] API fetch /packages/api-fetch [Package] HTML entities /packages/html-entities labels Jun 26, 2026
@github-actions github-actions Bot added [Package] Interactivity Router /packages/interactivity-router [Package] Fields /packages/fields [Package] Router /packages/router [Package] Theme /packages/theme [Package] UI /packages/ui [Package] Sync /packages/sync labels Jun 26, 2026
@ntsekouras

Copy link
Copy Markdown
Contributor

I think I like this approach more..

Another thing I keep thinking of is @Mamaduka's comment about moving more stuff to rich-text package. We could also move the keydown/input listeners- they're tied to those contexts since they are what dispatches the callbacks registered through those contexts.

By moving more into rich-text, every consumer (here the DataViews control) would eventually need less duplicate code.

Format types register keyboard-shortcut and input-event callbacks through
keyboardShortcutContext / inputEventContext; until now only the block-editor
RichText and the rich-text-control package knew how to dispatch them. Host
the two dispatch helpers next to the contexts they serve so any rich text
field can wire them without duplicating the glue.
The shell owns only the chrome: BaseControl + label, the contentEditable
element, and the popover-slot scaffolding with the blur/focus selection
heuristic (including document-level focus tracking for popover excursions).
It has no @wordpress/rich-text dependency; consumers inject the editable
behavior through editableRef and children and own the selection state via
onSelectedChange.
The richtext DataForm control becomes the rich-text assembly: it calls
useRichText, wires FormatEdit, the keyboard/input event listeners (now
private @wordpress/rich-text APIs), Enter/line-break handling, and format
input rules, and renders the presentational RichTextControl shell from
@wordpress/components. The dependency on @wordpress/rich-text-control is
replaced with @wordpress/rich-text, and the assembly is written in
TypeScript rather than vendored with ts-nocheck.
The presentational shell now lives in @wordpress/components and the
rich-text assembly in @wordpress/dataviews, so the package (and its
storybook, docs-manifest, tsconfig, and private-apis wiring) is no longer
needed. Nothing outside those two packages consumed it.
@adamsilverstein

Copy link
Copy Markdown
Member Author

Rebuilt this branch on the current move/rich-text-control-package tip and it's ready for a fresh look:

  • The unrelated collaboration/autosave changes are gone (they were merge-topology artifacts, not real edits — a linear rebuild removed them).
  • @ntsekouras's suggestion to move the keydown/input listeners into @wordpress/rich-text is done: shortcutsListener / inputEventsListener now live next to the contexts they serve, as private APIs (1ecd542).
  • Everything the base branch gained since the original spike is carried over: TypeScript throughout (no ts-nocheck vendoring), Enter/line-break handling, popover focus-out tracking, placeholder styles, and the DataForm Storybook story.

Locally: 39 control tests plus the full rich-text (218) and dataviews (290) suites green, lint clean. PR description updated to match.

@adamsilverstein

Copy link
Copy Markdown
Member Author

We could also move the keydown/input listeners - they're tied to those contexts since they are what dispatches the callbacks registered through those contexts.

@ntsekouras Done in 1ecd542: shortcutsListener / inputEventsListener now live in packages/rich-text/src/event-listeners.ts, right next to the contexts they serve, exposed via the package's private APIs. The DataViews assembly consumes them from @wordpress/rich-text instead of carrying its own copies, so any future rich text field gets the dispatch glue for free.

On the broader "move more into rich-text" point: #79828 moves RichTextShortcut / RichTextInputEvent there as a precursor, and with the listeners now hosted there too, the only assembly-specific glue left in DataViews is FormatEdit + the format input rules — which could follow the same path later if another consumer appears.

@github-actions

github-actions Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@andrewserong andrewserong 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.

This looks good to merge into the main PR to me, I like the approach of including this in the components package rather than the separate rich-text-control package, and the DataForm storybook entry continues to test well.

A couple of nits:

  • This PR removes the Storybook stories that were included in rich-text-control. Can we add these to the components package, too?
  • The readme is also removed. Is it worth adding a minimal README.md file in the target destination, too, with basic usage?

(Neither of the above need to block merging into the main PR)

LGTM!

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

Flaky tests detected in c2f71b9.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28768912990
📝 Reported issues:

@ciampo ciampo 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.

cc @WordPress/gutenberg-components , are we able to review the approach in this PR before it gets merged? (especially @mirka as the input controls expert)

I"m a bit stretched due to my involvement with the Gutenberg 23.6 release, not sure if/when I'll manage to take a look myself.

@adamsilverstein

adamsilverstein commented Jul 6, 2026 •

Copy link
Copy Markdown
Member Author

This looks good to merge into the main PR to me, I like the approach of including this in the components package rather than the separate rich-text-control package, and the DataForm storybook entry continues to test well.

A couple of nits:

  • This PR removes the Storybook stories that were included in rich-text-control. Can we add these to the components package, too?
  • The readme is also removed. Is it worth adding a minimal README.md file in the target destination, too, with basic usage?

(Neither of the above need to block merging into the main PR)

LGTM!

I'll go ahead and address final feedback before merging this!

Thanks!

Follow the components-package conventions: props live in a sibling
types.ts (picking shared props off BaseControlProps), and the component
signature wraps them in WordPressComponentProps so all standard HTML
div attributes pass through to the contentEditable element. Consumer
onFocus/onBlur handlers are chained ahead of the selection heuristic.
Addresses review feedback.
Form controls in the components package expose their underlying element
via forwardRef rather than bespoke ref props, and leave focus management
to the surrounding region rather than a focusOnMount prop. The rich-text
wiring now injects through the forwarded ref, and the DataViews consumer
implements its focus-on-mount behavior locally. Addresses review
feedback.
Follow the package convention of dual-mode state: the selection state
can be driven through an isSelected prop or left to the control via
useControlledValue (with defaultIsSelected), and children -- the format
assembly -- now mount only while the field is selected, so uncontrolled
consumers need no state of their own. The DataViews consumer stays
controlled and drops its manual children gating. Addresses review
feedback.
Popovers opened by format types no longer need a control-owned slot:
the Popover primitive already portals to an ambient Popover.Slot or its
body-level fallback container, so the private SlotFillProvider,
createPortal, and slot marker only duplicated that while fighting the
effort to consolidate popovers into a shared container. Blur handling
now recognizes the shared containers (ambient slot, fallback container,
@wordpress/ui compat overlay) instead of a private marker. Addresses
review feedback.
Restore the developer documentation that was lost when the standalone
rich-text-control package was folded into components: a status-private
story demonstrating the presentational shell and its selection-gated
children, plus a docs manifest so the README generates from the TSDoc
props. Addresses review feedback.
@adamsilverstein

adamsilverstein commented Jul 6, 2026 •

Copy link
Copy Markdown
Member Author

Addressed all review feedback so far:

  • Types moved to types.ts, and props now wrapped in WordPressComponentProps< …, 'div', false > so all standard HTML div props pass through (a27a3f2)
  • forwardRef to the editable element replaces the bespoke editableRef prop, and focusOnMount is removed — the DataViews consumer handles focus locally (4575f20)
  • Controlled/uncontrolled selection via useControlledValue: isSelected / defaultIsSelected / onSelectedChange, with children mounted only while selected (8114b7c)
  • Private SlotFill + createPortal removed — blur handling now recognizes the shared popover containers instead of owning a slot (4226c92)
  • Storybook story (status-private) and generated README restored per @andrewserong's suggestions (6d9fdc8)

The DataForm storybook entry and the full unit suites (components shell + DataViews assembly) pass.

The docs manifest is generated from the component docs; CI's
check-local-changes fails without this entry for the newly generated
README.
@adamsilverstein

Copy link
Copy Markdown
Member Author

This branch was merged into its base, so GitHub marked the PR as merged. #78471 now carries these changes (plus #79828 and a trunk sync) and is the single review point going forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Package] DataViews /packages/dataviews [Package] Private APIs /packages/private-apis [Package] Rich text /packages/rich-text [Status] In Progress Tracking issues with work in progress [Type] Feature New feature to highlight in changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants