Skip to content

RichTextControl: A11y and other minor bugs #80294

Open

Description

@Mamaduka

Extracted from #79604 (comment). Props to @ciampo.

This is tracking issue of follow-up fixes for the new RichTextControl component.

1. Complete the ARIA autocomplete contract. Fixed via #80403.

packages/dataviews/src/components/dataform-controls/richtext/control.tsx:503-526

[major] This new surface exposes the shared autocomplete hook's incomplete list-autocomplete semantics. The textbox ultimately receives aria-autocomplete="list", aria-owns, and aria-activedescendant, but no aria-controls or matching aria-haspopup; it also adds/removes aria-autocomplete based on whether results are currently visible instead of exposing expanded/collapsed state.

WAI-ARIA 1.2's aria-autocomplete definition requires list autocomplete to reference the suggestions with aria-controls and expose a matching popup type, and advises using expanded state rather than dynamically toggling aria-autocomplete. Since the behavior comes from useAutocompleteProps, I would fix the shared @wordpress/components hook rather than patching only DataViews, then add an integration test here for the textbox/listbox relationship.

2. Keep overlay placement out of field-level focus tracking - Fixed via #80324.

packages/dataviews/src/components/dataform-controls/richtext/control.tsx:550-617

[major] The per-control SlotFillProvider and body-portalled Popover.Slot make overlay placement part of this DataViews field solely so focus ownership can be tested through DOM containment. This creates a separate overlay root for every field, bypasses the shared/default Popover container and cuts across the ongoing central overlay-slot consolidation. It also requires the additional container state, ref containment checks, and document-level focusout listener above.

Could we let registered formats keep using the normal Popover, then place RichTextControlShell and FormatEdit under one focus boundary? onFocusCapture can cancel a pending deselection, while a deferred onBlurCapture can deselect when focus actually leaves. Focus events from portalled Popovers bubble through the React tree, so this recognizes overlays owned by the field without depending on their DOM container; unrelated overlays remain outside the boundary. That would remove the local SlotFillProvider, Popover.Slot, body portal, containment logic, and document listener. The Popover should remain portalled through its default behavior rather than rendered inline, because the notes sidebar has clipping and scrolling ancestors. The existing own-popover, leave-popover, and unrelated-popover tests can exercise the same behavior against the default container.

3. Restore caret position when a format popover returns focus. Fixed via #80396.

packages/dataviews/src/components/dataform-controls/richtext/control.tsx:346-348

Canceling a format popover — most visibly, the inline link UI dismissed via Escape — returns focus to the field via onFocus(), but the caret lands at the start of the text rather than the previous selection. The block-editor RichText (packages/block-editor/src/components/rich-text/index.js) has an identical onFocus handler and does not exhibit this.

The onFocus handler is not the cause. On focus-return, the rich-text focus-in handler runs applyRecord( record.current, { domOnly: true } ) (packages/rich-text/src/hook/event-listeners/input-and-selection.js:307-308), and { domOnly: true } intentionally skips selection restoration (packages/rich-text/src/to-dom.js:228) — so the caret is left wherever the browser dropped it after the popover excursion. In the block editor, the selection lives in blockEditorStore and is reapplied to the DOM by the store/writing-flow machinery, so the caret survives. The standalone control keeps selection in an isolated local state with nothing re-applying it, so it relies on the browser preserving the DOM selection while the body-portalled popover held focus, which does not survive, and the caret falls back to offset 0.

The recommended fix is to make the standalone (non-editableRoot) branch of the rich-text focusin handler restore the selection like the editableRoot branch just above it (input-and-selection.js:278-288): when isSelected and the DOM selection is no longer inside the element, do a full applyRecord( record.current ) instead of the domOnly variant. This fixes the dataforms field without regressing the block editor, whose DOM selection is still normally inside the element, and keeps the domOnly fast path.

4. Replace the field's SlotFill isolation with a format-host toolbar capability

Extracted from #80324 (review).

packages/dataviews/src/components/dataform-controls/richtext/control.tsx:467-519 (after #80324)

FormatEdit mounts every registered format's edit component. Core formats such as bold, italic, link, and code render RichTextToolbarButton, which registers a Fill named RichText.ToolbarControls.*; the block editor's FormatToolbar renders matching Slots under the same outer provider. Without a provider of its own, this field's controls can therefore reach a surrounding block toolbar. Those controls close over the standalone field's value, selection, onChange, and onFocus, so rendering them in the block toolbar makes them appear to belong to the block while they mutate the note or DataForm field instead. #80324 retains the local SlotFillProvider as a temporary compatibility boundary for exactly this reason.

Ideally, a registered format would not expose shortcuts/input handlers, inline UI such as the link Popover, and toolbar contributions through one edit component. Those concerns would be separate contributions, and each rich-text host would render only the ones it supports. A standalone field could then enable shortcuts and inline UI without participating in a block toolbar at all. That contract cannot be replaced without breaking long-standing public APIs: registerFormatType and its combined edit callback date to October 2018, and RichTextToolbarButton has been part of the public format API since November 2018.

The backward-compatible path is to replace the generic SlotFill isolation with an explicit format-host capability. @wordpress/rich-text already provides the private host contexts used for shortcuts and input events; add a similarly private format-edit context whose toolbar capability defaults to true. The DataViews host opts out around FormatEdit, and RichTextToolbarButton checks that capability before registering its Fill. For example, the host-side shape could be:

<FormatEditContext.Provider value={ { toolbar: false } }>
	<FormatEdit ... />
</FormatEditContext.Provider>

This should describe host capability — not a block-editor slot destination — and retain the existing RichText.ToolbarControls.* names and default behavior. Existing formats using the documented RichTextToolbarButton path therefore behave as before; only this private standalone host opts out. A format that bypasses that component and targets the literal SlotFill names would not honor the capability, but those names are undocumented implementation details and should not define the cross-package contract.

Once that targeted boundary exists, remove the local SlotFillProvider from this control. Tests should prove that the context defaults to the current toolbar behavior and that the DataViews opt-out prevents surrounding toolbar fills without changing shortcuts or real Popovers. Whether standalone rich-text fields should instead expose their own visible toolbar is a separate product/accessibility decision.

Activity

  1. added
    [Focus] Accessibility (a11y)
    [Type] Code Quality
    [Type] Tracking Issue
    [Package] DataViews
    on Jul 15, 2026
  2. added
    Needs Accessibility Feedback
    on Jul 16, 2026
  3. t-hamano commented on Aug 6, 2026

    @t-hamano
    Contributor
    1. Replace the field's SlotFill isolation with a format-host toolbar capability

    I believe this is the only remaining problem in this issue, but since it will likely be difficult to resolve in 7.1, I'd like to punt it to 7.2.

  4. moved this from 🏗️ In Progress to 🦵 Punted to 7.2 in WordPress 7.1 Editor Taskson Aug 6, 2026
  5. Mamaduka commented on Aug 6, 2026

    @Mamaduka
    MemberAuthor

    Yes, we can punt this. Thanks for checking, @t-hamano!

  6. ciampo commented on Aug 25, 2026

    @ciampo
    Contributor

    Now that the 7.2 development cycle has started, would it be a good time to work on a fix for the last point? Would it make it on time for the next 7.1 minor, even?

  7. Mamaduka commented on Aug 25, 2026

    @Mamaduka
    MemberAuthor

    I'll try to have a look, but I don't think it's super urgent for a minor release, since nothing is actually broken and it's more of a larger refactoring.

    The control has moved to collab-sidebar in #81430, so there's only one consumer for it.

  8. moved this from 📥 Todo to 🦵 Punted to 7.3 in WordPress 7.2 Editor Taskson Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs Accessibility Feedback[Focus] Accessibility (a11y)[Package] DataViews[Type] Code Quality[Type] Tracking Issue

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions