Skip to content

Widget Primitives: Let a host give widgets their translated title - #84738

Open
adamwoodnz wants to merge 9 commits into
WordPress:trunkfrom
adamwoodnz:add/widget-host-title
Open

adamwoodnz wants to merge 9 commits into
WordPress:trunkfrom
adamwoodnz:add/widget-host-title

Conversation

@adamwoodnz

@adamwoodnz adamwoodnz commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What?

Closes #84204

Adds an optional, translated title to WidgetHost. The dashboard gives each widget its type's title through it.

Why?

A widget can now name its own content from the title the dashboard already shows, in the user's language. A focusable chart can say "Sales by device chart" to a screen reader. Before, a widget had to hardcode a second copy of its title, which could drift from the title the widget declares and was never translated, so screen reader users heard English.

How?

  • @wordpress/widget-primitives: WidgetHost.title?: string. It rides the existing provider merge, so a per-widget provider keeps the host's links. Docs on the Widget Host Storybook page and in the README.
  • @wordpress/widget-dashboard: the WidgetRender adapter already nests a per-instance WidgetHostProvider for actions. It now also sets title: widgetType.title. WidgetFrame mounts this adapter for the tile, the drag preview and the Add widget preview.

The host passes a string, not the title element's id: aria-labelledby joins text in a fixed order, so a translated name built around the title could not place it.

Compatibility: additive and optional. A widget on an older host reads title as undefined and uses its own name; an older widget ignores the field. title shares the existing WidgetHostContext, so it has the same single-package-copy requirement as links and actions. Mixed-version combinations were not built in an isolated consumer.

Review focus: the title doc comment in widget-host.tsx and the contract wording in widget-host.md.

Testing Instructions

  1. npm run test:unit:vitest -- packages/widget-dashboard packages/widget-primitives routes/dashboard
  2. widget-host-title.jsdom.test.tsx mounts a WidgetDashboard with a widget that labels a figure with `Chart: ${ title }` and finds it by that name.

Verified locally: 31 files, 277 tests pass (jsdom, node and browser). The new test fails without the adapter change (aria-label="Chart: undefined"). tsc --build on both packages and eslint on the changed files are clean.

Testing Instructions for Keyboard

No visible UI change.

Screenshots or screencast

None: no visible UI change.

Use of AI Tools

Implemented with Claude Code (Claude Opus), reviewed by the author.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

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: adamwoodnz <adamwood@git.wordpress.org>

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

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

@github-actions github-actions Bot added [Package] Widget primitives /packages/widget-primitives [Package] Widget Dashboard /packages/widget-dashboard labels Oct 14, 2026
@adamwoodnz adamwoodnz added the [Type] Enhancement A suggestion for improvement. label Oct 14, 2026
@adamwoodnz adamwoodnz self-assigned this Oct 14, 2026
@adamwoodnz adamwoodnz moved this from Todo to In Progress in @adamwoodnz's WIP Oct 14, 2026
@adamwoodnz adamwoodnz moved this from In Progress to Draft (PR only) in @adamwoodnz's WIP Oct 14, 2026
@adamwoodnz

Copy link
Copy Markdown
Contributor Author

Codex review

The title capability is passed per widget render and is shared by dashboard tiles and picker previews through WidgetFrame. No correctness, contract, accessibility, or regression issues were identified.

@adamwoodnz
adamwoodnz marked this pull request as ready for review October 14, 2026 22:07
@adamwoodnz
adamwoodnz requested a review from retrofox as a code owner October 14, 2026 22:07
@adamwoodnz adamwoodnz moved this from Draft (PR only) to In Review (PR only) in @adamwoodnz's WIP Oct 14, 2026
@adamwoodnz
adamwoodnz force-pushed the add/widget-host-title branch from aeeb9a3 to 4532cd9 Compare October 15, 2026 22:15
A widget's render component could not read its own title, so content
that needs an accessible name built from it, such as a focusable
chart, had to hardcode a second copy with __(). That copy drifts from
widget.json, and __( manifest.title ) is not a string literal, so the
title never reaches the script's translation file.

The host already holds the translated title. An optional title on
WidgetHost lets it pass that string to the widget through context,
reachable from any component below the render. A string, not an id,
because aria-labelledby cannot reorder "<title> chart" for locales
that put the noun first.
The dashboard renders widgetType.title in each header but did not pass
it to the widget, so widgets on it could not use the new title host
capability. The per-instance provider that binds actions now carries
the title too. WidgetFrame mounts it for the tile, the drag preview and
the Add widget preview, so all three get it.
The title example sat between the HostLink composition and the sentence that points at its story, so that sentence read as if it described the title snippet.
Gutenberg changelogs reference the PR that ships a change, not the issue that asked for it.
How a widget phrases a name around its title belongs to that widget and its translators. An example here would drift from what consumers actually ship.
The rationale for the title capability lives in the issue and PR. The docs only need to say what the value is.
The docs say what title is and who provides it. How a widget uses it is the widget's call.
Match the colon format consumers use, so the test does not model a word-order pattern that breaks in other locales.
Moving the title example earlier also moved the useWidgetHost note away from the HostLink section it belongs to. With the example gone, the note returns to its trunk position. The title doc comment drops a usage note the sibling capabilities do not carry.
@adamwoodnz
adamwoodnz force-pushed the add/widget-host-title branch from 4532cd9 to 87d0e52 Compare October 19, 2026 19:43

This branch has not been deployed

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

Labels

[Package] Widget Dashboard /packages/widget-dashboard [Package] Widget primitives /packages/widget-primitives [Type] Enhancement A suggestion for improvement.

Projects

Status: In Review (PR only)

Development

Successfully merging this pull request may close these issues.

Widget Primitives: Let a host give widgets their translated title

1 participant