From 56978f0fbedc886dbe732dee7e0656d60a5aed91 Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Tue, 25 Aug 2026 19:36:53 +0300 Subject: [PATCH 1/5] Stats: replace Button with LinkButton for a link --- .../premium-analytics/changelog/update-ui-link-button | 3 +++ .../premium-analytics/packages/externals/src/index.ts | 1 + .../premium-analytics/routes/post-detail/stage.tsx | 11 +++++------ 3 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 projects/packages/premium-analytics/changelog/update-ui-link-button diff --git a/projects/packages/premium-analytics/changelog/update-ui-link-button b/projects/packages/premium-analytics/changelog/update-ui-link-button new file mode 100644 index 000000000000..a0505d317808 --- /dev/null +++ b/projects/packages/premium-analytics/changelog/update-ui-link-button @@ -0,0 +1,3 @@ +Significance: patch +Type: changed +Comment: Make the post-detail View post action a real link. diff --git a/projects/packages/premium-analytics/packages/externals/src/index.ts b/projects/packages/premium-analytics/packages/externals/src/index.ts index 3246ad98833a..1a3cf7f38079 100644 --- a/projects/packages/premium-analytics/packages/externals/src/index.ts +++ b/projects/packages/premium-analytics/packages/externals/src/index.ts @@ -71,6 +71,7 @@ export { DateRangeCalendar } from '@automattic/ui'; export { Button, EmptyState, + LinkButton, Field as FormField, Fieldset, Icon, diff --git a/projects/packages/premium-analytics/routes/post-detail/stage.tsx b/projects/packages/premium-analytics/routes/post-detail/stage.tsx index 045429b8a1b8..cfcb4015c577 100644 --- a/projects/packages/premium-analytics/routes/post-detail/stage.tsx +++ b/projects/packages/premium-analytics/routes/post-detail/stage.tsx @@ -3,7 +3,7 @@ import { GlobalErrorProvider, ReportScopeProvider, } from '@jetpack-premium-analytics/data'; -import { Button } from '@jetpack-premium-analytics/externals'; +import { LinkButton } from '@jetpack-premium-analytics/externals'; import { useReportDateFilters } from '@jetpack-premium-analytics/routing'; import { DateFiltersPanel, @@ -142,19 +142,18 @@ function PostDetail(): JSX.Element { breadcrumbs={ } actions={ publicUrl ? ( - + ) : undefined } className={ styles.page } From 3384820a53e78648851237d3118587df05a66fab Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Tue, 25 Aug 2026 21:07:03 +0300 Subject: [PATCH 2/5] Fix test --- .../premium-analytics/routes/post-detail/stage.test.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx b/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx index d52b6b4eb413..e942e79265ad 100644 --- a/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx +++ b/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx @@ -188,7 +188,8 @@ describe( 'post detail stage', () => { render( stage() ); - const action = screen.getByRole( 'link', { name: 'View post' } ); + // `openInNewTab` appends a screen-reader hint to the accessible name. + const action = screen.getByRole( 'link', { name: 'View post(opens in a new tab)' } ); expect( action ).toHaveAttribute( 'href', 'https://example.com/hello-world/' ); expect( action ).toHaveAttribute( 'target', '_blank' ); expect( action ).toHaveAttribute( 'rel', 'noopener noreferrer' ); @@ -199,11 +200,13 @@ describe( 'post detail stage', () => { render( stage() ); - expect( screen.getByRole( 'link', { name: 'View page' } ) ).toHaveAttribute( + expect( screen.getByRole( 'link', { name: 'View page(opens in a new tab)' } ) ).toHaveAttribute( 'href', 'https://example.com/about/' ); - expect( screen.queryByRole( 'link', { name: 'View post' } ) ).not.toBeInTheDocument(); + expect( + screen.queryByRole( 'link', { name: 'View post(opens in a new tab)' } ) + ).not.toBeInTheDocument(); } ); it( 'omits the action while the post URL is unresolved', () => { From 99cc7c1678fc7a9e7dd8d50c50c3c037c929e335 Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Tue, 25 Aug 2026 21:09:10 +0300 Subject: [PATCH 3/5] Don't expect rel in LinkButton --- .../packages/premium-analytics/routes/post-detail/stage.test.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx b/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx index e942e79265ad..5088e4a70632 100644 --- a/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx +++ b/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx @@ -192,7 +192,6 @@ describe( 'post detail stage', () => { const action = screen.getByRole( 'link', { name: 'View post(opens in a new tab)' } ); expect( action ).toHaveAttribute( 'href', 'https://example.com/hello-world/' ); expect( action ).toHaveAttribute( 'target', '_blank' ); - expect( action ).toHaveAttribute( 'rel', 'noopener noreferrer' ); } ); it( 'labels the action View page for a page', () => { From 814f7195eeafcbbf7e68236a5b444174c0a093ce Mon Sep 17 00:00:00 2001 From: Mikael Korpela Date: Tue, 25 Aug 2026 21:09:26 +0300 Subject: [PATCH 4/5] Clean out style workaround --- .../routes/post-detail/stage.module.scss | 9 --------- 1 file changed, 9 deletions(-) diff --git a/projects/packages/premium-analytics/routes/post-detail/stage.module.scss b/projects/packages/premium-analytics/routes/post-detail/stage.module.scss index 49053bf6a7fb..6fcb59e3a091 100644 --- a/projects/packages/premium-analytics/routes/post-detail/stage.module.scss +++ b/projects/packages/premium-analytics/routes/post-detail/stage.module.scss @@ -95,12 +95,3 @@ flex: 0 0 auto; margin-inline-start: auto; } - -// The header action is a Button rendered as an anchor, so it can carry a real -// href to the live post. @wordpress/ui styles the button inside `@layer wp-ui`, -// and wp-admin colours bare anchors outside any cascade layer — unlayered wins -// over layered whatever the specificity, so admin's link blue overrode the -// button foreground. Re-apply the button's own colour from here (unlayered). -.viewPost:any-link { - color: var(--wp-ui-button-foreground-color); -} From 91372ebf2c486ac48d0c732b7dd2154013540327 Mon Sep 17 00:00:00 2001 From: Nikhil Date: Wed, 26 Aug 2026 07:07:16 +0530 Subject: [PATCH 5/5] Fix vacuous action tests and drop the removed viewPost class The accessible name now ends in '(opens in a new tab)', so the anchored regex in the two 'omits the action' tests could never match a rendered link. Drop the end anchor so they fail again when the URL guard is removed. The viewPost class was deleted with the any-link workaround, so the className prop resolved to undefined. --- .../premium-analytics/routes/post-detail/stage.test.tsx | 4 ++-- .../packages/premium-analytics/routes/post-detail/stage.tsx | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx b/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx index 5088e4a70632..50b863968b6b 100644 --- a/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx +++ b/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx @@ -213,7 +213,7 @@ describe( 'post detail stage', () => { render( stage() ); - expect( screen.queryByRole( 'link', { name: /^View (post|page)$/ } ) ).not.toBeInTheDocument(); + expect( screen.queryByRole( 'link', { name: /^View (post|page)/ } ) ).not.toBeInTheDocument(); } ); it( 'omits the action when the post URL carries an unsupported scheme', () => { @@ -221,7 +221,7 @@ describe( 'post detail stage', () => { render( stage() ); - expect( screen.queryByRole( 'link', { name: /^View (post|page)$/ } ) ).not.toBeInTheDocument(); + expect( screen.queryByRole( 'link', { name: /^View (post|page)/ } ) ).not.toBeInTheDocument(); } ); // One declaration drives both halves: the panel reads it to drop the Compare diff --git a/projects/packages/premium-analytics/routes/post-detail/stage.tsx b/projects/packages/premium-analytics/routes/post-detail/stage.tsx index cfcb4015c577..ae4294140c37 100644 --- a/projects/packages/premium-analytics/routes/post-detail/stage.tsx +++ b/projects/packages/premium-analytics/routes/post-detail/stage.tsx @@ -146,7 +146,6 @@ function PostDetail(): JSX.Element { variant="solid" tone="neutral" size="compact" - className={ styles.viewPost } href={ publicUrl } openInNewTab >