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.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); -} 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..50b863968b6b 100644 --- a/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx +++ b/projects/packages/premium-analytics/routes/post-detail/stage.test.tsx @@ -188,10 +188,10 @@ 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' ); } ); it( 'labels the action View page for a page', () => { @@ -199,11 +199,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', () => { @@ -211,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', () => { @@ -219,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 045429b8a1b8..ae4294140c37 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,17 @@ function PostDetail(): JSX.Element { breadcrumbs={ } actions={ publicUrl ? ( - + ) : undefined } className={ styles.page }