Repository navigation
DataViews: Back richtext control with a @wordpress/components shell (alt to #78471) - #79345
Conversation
|
Size Change: -1.95 kB (-0.03%) Total Size: 7.64 MB 📦 View Changed
|
|
I think I like this approach more.. Another thing I keep thinking of is @Mamaduka's comment about moving more stuff to By moving more into |
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.
|
Rebuilt this branch on the current
Locally: 39 control tests plus the full rich-text (218) and dataviews (290) suites green, lint clean. PR description updated to match. |
…into rebuild/rich-text-shell-in-components
@ntsekouras Done in 1ecd542: On the broader "move more into |
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
andrewserong
left a comment
There was a problem hiding this comment.
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 thecomponentspackage, 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!
|
Flaky tests detected in c2f71b9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28768912990
|
ciampo
left a comment
There was a problem hiding this comment.
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.
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.
|
Addressed all review feedback so far:
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.
Summary
Stacked on #78471. This implements the counter-proposal raised in #78471 review by @ciampo and @mirka: instead of a dedicated
@wordpress/rich-text-controlpackage that hard-wires@wordpress/rich-text, host a presentational shell in@wordpress/componentsand 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-textgains private event-listener helperskeyboardShortcutContext/inputEventContextthey serve, exposed as private APIs (shortcutsListener,inputEventsListener). Consumers no longer duplicate this glue.@wordpress/componentsgains a private, presentationalRichTextControlBaseControl+ label, thecontentEditableelement, and thePopover.Slotscaffolding plus the blur/focus selection heuristic (including the document-level focus tracking that deselects the field once focus leaves a popover it opened).@wordpress/rich-textdependency. The editable behavior (value, formatting, keyboard shortcuts) is injected by the consumer througheditableRefandchildren; selection is controlled viaonSelectedChange.@wordpress/ui-future questions stay out of scope).@wordpress/dataviewsowns the rich-text "assembly"richtextDataForm control becomes the assembly: it callsuseRichText, wiresFormatEdit, the event listeners (from@wordpress/rich-text), Enter/line-break handling, and format input rules, and renders the components shell.@ts-nocheckvendoring.@wordpress/rich-text-controlis removed.Why this shape
The ref-cycle that makes a "clean" split look hard (
useRichTextproduces the ref the shell needs, butisSelectedfeeds back intouseRichText) resolves by making the shell a controlled component: the assembly ownsisSelected, the shell drives the focus/blur transitions viaonSelectedChange. Standard React data flow; state lives in the assembly, DOM heuristics live in the shell.Net effect:
@wordpress/componentsgains a reusable presentational primitive,@wordpress/rich-textstays 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-controlnpm package, because there isn't one.Test coverage
Coverage is preserved and split along the new boundary:
rich-text-control/test): presentational shell — label/aria,id, className merge, focus-on-mount,editableRefattachment, and the controlled-selection / popover-slot blur heuristic including the popover-exit focus tracking (14 tests).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).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)