Skip to content

Premium Analytics: Build the metric cards on a CardTabs primitive instead of restyling Tabs - #54468

Merged
retrofox merged 10 commits into
trunkfrom
update/card-tabs-primitive
Nov 5, 2026
Merged

retrofox merged 10 commits into
trunkfrom
update/card-tabs-primitive

Conversation

@retrofox

@retrofox retrofox commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes STATS-591

Proposed changes

A CardTabs primitive in packages/ui

The metric cards in the chart widgets were the Tabs of @wordpress/ui restyled as cards.

Tabs ships an indicator, a 48px height, and hover and focus chrome on pseudo-elements, with no unstyled variant, so the widget undid them through selectors on upstream internals (.tab > svg, [role="presentation"], .tab::after), and every @wordpress/ui release broke one of them (#50139, #53135, #53869, #54385).

CardTabs mirrors the Tabs API (Root, List, Tab, Panel) on @base-ui/react/tabs, the library @wordpress/ui itself builds on, with its own stylesheet on WPDS tokens: the interactive neutral tokens for rest and hover, the brand weak active token for the selected card, as Button and Menu use them, an inset focus ring, and a grid that wraps on its own.

@base-ui/react becomes a direct dependency of the package, pinned to the version @wordpress/ui resolves to, and an ESLint rule keeps it out of every other module.

MetricTabsChart renders its tabbed layout on it

The tabbed branch switches to CardTabs and the stylesheet drops every override of the Tabs internals.

The single-metric headline and the narrow-tile dropdown are unchanged. The column balancing the component computes keeps working through --jpa-card-tabs-columns, and the minimum card width it already knows is handed to the list as --jpa-card-tabs-min-inline-size, so that number lives in one place.

The card face is phrasing content

A <button> allows phrasing content only, and the card held three <div>s: the Stack under MetricWithComparison and MetricDelta, and VisuallyHidden. Both metric components take a render prop now, and the card passes <span /> through it.

What changes on screen

Hover goes from the light blue fill to the neutral hover tone the rest of the design system uses, the selected card takes the brand weak active fill, and the focus ring follows the card edge instead of being clipped by the widget chrome.

Related product discussion/links

  • STATS-591
  • p1793253198813149-slack-premium-analytics
  • p1793257766146359-slack-design-systems

Does this pull request change what data or activity we track or use?

No.

Testing instructions

Install and build

jetpack install packages/premium-analytics
jetpack build packages/premium-analytics

Then open the Premium Analytics dashboard on a connected site.

Screen.Recording.2026-11-03.at.4.05.26.PM.mov

The cards

In the Traffic summary and Subscriber summary widgets, hover a card: it takes a light grey fill, not the light blue one. Click a card: it takes the light blue fill and the chart switches. Tab into the widget and move between the cards with the arrow keys: the focus ring is drawn inside the card and nothing is clipped, and Enter or Space selects the focused card.

Wrapping and the dropdown

Resize a widget down: the cards wrap into rows before the switch to the dropdown, and the dropdown looks as before. The Store performance widget and the single-figure widgets (Post views, Email performance) look as before.

Storybook

Run pnpm run storybook:dev in the package and open Packages/Premium Analytics/UI/CardTabs: the Wrapping story shows two rows at 360px. The MetricTabsChart stories under Widgets Toolkit show the cards in the widget.

image

Tests

pnpm run test packages/ui/src/card-tabs packages/widgets-toolkit/src/components/metric-tabs-chart passes, as do the suites of the widgets that mount the chart.

Base UI tabs on WPDS tokens, mirroring the Tabs API of @wordpress/ui
lets a card render the value and delta as spans inside a button
drops every override of the Tabs internals from the stylesheet
@retrofox retrofox added Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Nov 3, 2026
@retrofox
retrofox requested a review from a team as a code owner November 3, 2026 13:05
@retrofox retrofox self-assigned this Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the update/card-tabs-primitive branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack update/card-tabs-primitive
bin/jetpack-downloader test jetpack-mu-wpcom-plugin update/card-tabs-primitive

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: December 8, 2026
    • Code freeze: December 7, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.


Premium Analytics plugin:

No scheduled milestone found for this plugin.

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@retrofox retrofox added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Nov 3, 2026
@retrofox
retrofox requested a review from Nikschavan November 3, 2026 15:13
drops the unused prop types and the gap custom property
the ui barrel re-exports it by name, as the other folders
@jp-launch-control

jp-launch-control Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

3 files are newly checked for coverage.

File Coverage
projects/packages/premium-analytics/packages/ui/src/card-tabs/card-tabs.tsx 8/8 (100.00%) 💚
projects/packages/premium-analytics/packages/ui/src/card-tabs/index.ts 0/0 (—%) 🤷

Full summary · PHP report · JS report

Coverage check overridden by Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR .

dognose24
dognose24 previously approved these changes Nov 4, 2026

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

Read through against @base-ui/react and @wordpress/ui: manual activation (Enter/Space), the RTL DirectionProvider, mounting only the selected panel, the phrasing content inside the button and the tracking call all match what the restyled Tabs did. Approving; three small things, none blocking.

  • The failing check is Code coverage (PHP, 1 of 1): the autoloader package's tests hit curl error 28 fetching from packagist (run 41663911176). Nothing in this PR touches PHP, so gh run rerun 41663911176 --failed should clear it.
  • Changelog: plugins/stats bundles packages/premium-analytics and ships this dashboard, so it needs an entry too, next to the plugins/jetpack one, e.g. jp changelog add plugins/stats -s patch -t changed -e "Premium Analytics: Give the metric cards the design system’s hover, selected and focus states."
  • tests/single-copy-modules.cjs still says @base-ui/react is something the package does not depend on directly; this PR makes it a direct dependency, so that sentence now points the wrong way.
  • Nit: card-tabs.test.tsx, the arrow-keys test renders with disabledKey: 'revenue' but only ever presses ArrowLeft towards Orders, so the disabled card is never exercised. Either add an ArrowRight that expects focus to skip Revenue, or drop the option.

@retrofox retrofox added the Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR label Nov 4, 2026
Nikschavan
Nikschavan previously approved these changes Nov 5, 2026

@Nikschavan Nikschavan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, the changes look good. I left a few comments inline, and none of them block this: one about where Base UI gets compiled, one about a missing test for the phrasing content, and a small docblock wording.

What I checked: I built the branch and opened the dashboard. Hovering a card gives it the grey fill, and the selected card keeps the brand fill. Arrow keys move the inset focus ring between cards, and Enter selects the focused card. At phone width the cards still change into the dropdown.

Hover and selected Keyboard focus
Hovering Orders gives it the grey fill while Net sales stays selected The focus ring sits inside the Orders card after ArrowRight
Traffic summary cards at 1280px At 390px the cards change into the dropdown

// eslint-disable-next-line no-restricted-imports -- The one module that compiles Base UI in; see the ESLint rule.
import { DirectionProvider } from '@base-ui/react/direction-provider';
// eslint-disable-next-line no-restricted-imports -- The one module that compiles Base UI in; see the ESLint rule.
import { Tabs } from '@base-ui/react/tabs';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This compiles Base UI into the ui module a second time: @wordpress/ui already brings the same @base-ui/react@1.9.0 into externals through the Tabs it re-exports. Re-exporting Tabs and DirectionProvider from @base-ui/react in externals would let the bundler reuse that copy, and the ESLint rule could then point at externals the way the @wordpress/ui one does. Is keeping Base UI in ui an intended trade-off?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. That makes sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's externalize them to avoid duplications.

</span>
) : (
<MetricWithComparison
render={ <span /> }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in the suite checks that the card face stays phrasing content: with all three render={ <span /> } props removed, the MetricTabsChart tests still pass. An assertion that no tab contains a div, in one of the existing multi-metric cases, would stop a later change to MetricWithComparison or VisuallyHidden from putting block elements back into the button. Fine as a follow-up if you want to keep this one small.

} from './types';

/**
* Groups the cards and their panels: the `Tabs` of `@wordpress/ui` with each

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads as if Root wraps the Tabs of @wordpress/ui, but it builds on Base UI directly. "Mirrors the Tabs API of @wordpress/ui" would match what the code does.

reuses the copy @wordpress/ui compiles in, instead of a second one in ui
fails when its version drifts from the one @wordpress/ui resolves
catches a card face part falling back to a div inside the tab button
it builds on Base UI; it does not wrap the Tabs of @wordpress/ui
@retrofox
retrofox merged commit 88c2141 into trunk Nov 5, 2026
133 checks passed
@retrofox
retrofox deleted the update/card-tabs-primitive branch November 5, 2026 15:07
@github-actions github-actions Bot removed the [Status] Needs Review This PR is ready for review. label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Coverage tests to be added later Use to ignore the Code coverage requirement check when tests will be added in a follow-up PR Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Package] Premium Analytics [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Plugin] Premium Analytics [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants