Repository navigation
Premium Analytics: Build the metric cards on a CardTabs primitive instead of restyling Tabs - #54468
Conversation
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
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
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:
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:
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. |
drops the unused prop types and the gap custom property
the ui barrel re-exports it by name, as the other folders
Code Coverage Summary3 files are newly checked for coverage.
Full summary · PHP report · JS report Coverage check overridden by
Coverage tests to be added later
|
dognose24
left a comment
There was a problem hiding this comment.
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 hitcurl error 28fetching from packagist (run 41663911176). Nothing in this PR touches PHP, sogh run rerun 41663911176 --failedshould clear it. - Changelog:
plugins/statsbundlespackages/premium-analyticsand ships this dashboard, so it needs an entry too, next to theplugins/jetpackone, 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.cjsstill says@base-ui/reactis 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 withdisabledKey: 'revenue'but only ever pressesArrowLefttowards Orders, so the disabled card is never exercised. Either add anArrowRightthat expects focus to skip Revenue, or drop the option.
Nikschavan
left a comment
There was a problem hiding this comment.
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 |
|---|---|
![]() |
![]() |
![]() |
![]() |
| // 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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Good call. That makes sense.
There was a problem hiding this comment.
Let's externalize them to avoid duplications.
| </span> | ||
| ) : ( | ||
| <MetricWithComparison | ||
| render={ <span /> } |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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




Fixes STATS-591
Proposed changes
A
CardTabsprimitive inpackages/uiThe metric cards in the chart widgets were the
Tabsof@wordpress/uirestyled as cards.Tabsships 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/uirelease broke one of them (#50139, #53135, #53869, #54385).CardTabsmirrors theTabsAPI (Root,List,Tab,Panel) on@base-ui/react/tabs, the library@wordpress/uiitself 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/reactbecomes a direct dependency of the package, pinned to the version@wordpress/uiresolves to, and an ESLint rule keeps it out of every other module.MetricTabsChartrenders its tabbed layout on itThe tabbed branch switches to
CardTabsand the stylesheet drops every override of theTabsinternals.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: theStackunderMetricWithComparisonandMetricDelta, andVisuallyHidden. Both metric components take arenderprop 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
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Install and build
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:devin the package and openPackages/Premium Analytics/UI/CardTabs: theWrappingstory shows two rows at 360px. TheMetricTabsChartstories under Widgets Toolkit show the cards in the widget.Tests
pnpm run test packages/ui/src/card-tabs packages/widgets-toolkit/src/components/metric-tabs-chartpasses, as do the suites of the widgets that mount the chart.