Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions projects/js-packages/base-styles/admin-page-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
// @automattic/jetpack-components)
// @wordpress/admin-ui: .admin-ui-page, .admin-ui-page__header
// <JetpackFooter>: .jetpack-footer
// Tabs wrapper convention: .jp-admin-page-tabs (consumer-applied div that
// wraps `@wordpress/ui`
// `Tabs.List`; see the
// "Tabs strip" section
// below)

// Implementation note — `postcss-custom-properties` with `preserve: false`:
// several consumer packages in this monorepo (publicize, videopress, search,
Expand Down Expand Up @@ -187,6 +192,16 @@ $jp-breakpoint-mobile: 782px;
flex-shrink: 0; // pinned at top of the flex column.
}

// When the page hosts a tabs strip, drop the header's bottom border AND
// its bottom padding so the strip sits flush against the header. The
// strip's own hairline becomes the only divider between header and tab
// content. Same `:has()` pattern used elsewhere in this mixin to react
// to the page's content shape.
.admin-ui-page:has(.jp-admin-page-tabs) .admin-ui-page__header {
border-bottom: none;
padding-bottom: 0;
}

// The scrollable middle. <AdminPage> does not pass `hasPadding` to
// admin-ui's <Page>, so `.admin-ui-page__content` is not rendered —
// children drop in as direct descendants of `.admin-ui-page`. Target
Expand All @@ -208,6 +223,43 @@ $jp-breakpoint-mobile: 782px;
flex-shrink: 0;
}

// ── Tabs strip (`@wordpress/ui` Tabs hosted inside the page) ─────
// Consumers that render `Tabs.List` from `@wordpress/ui` inside an
// AdminPage should wrap it in `<div class="jp-admin-page-tabs">`.
// The wrapper exists because `Tabs.List` ships with `width: fit-content`
// (so its tabs don't stretch to fill the row); a `border-bottom` on the
// list shrinks to the tabs' width. The wrapper takes the full block
// width of the panel area, so the hairline spans the column.

// `position: sticky` pins the strip to the top of the scrollable middle
// (`.admin-ui-page > :not(.admin-ui-page__header):not(.jetpack-footer)`),
// which is the local opt-in equivalent of admin-ui's native sticky
// header — disabled globally by `<AdminPage>` per JETPACK-1386. Pinning
// the tabs strip here keeps cross-section navigation accessible while
// content scrolls underneath.

// Surface + hairline use the same `--wpds-*` design tokens that
// `@wordpress/admin-ui` applies to `.admin-ui-page__header`, so the
// tabs strip reads as a visual continuation of the page header and
// tracks any future token (theme/dark-mode) changes automatically.
.jp-admin-page-tabs {
position: sticky;
top: 0;
z-index: 10;
background: var(--wpds-color-bg-surface-neutral-strong);
border-bottom: var(--wpds-border-width-xs) solid var(--wpds-color-stroke-surface-neutral-weak);

// Align tab buttons' inline padding with the page header's
// horizontal padding (admin-ui ships `.admin-ui-page__header`
// at `padding-inline: var(--wpds-dimension-padding-2xl)`).
// `@wordpress/ui` Tabs default the buttons to `padding-inline:
// var(--wpds-dimension-padding-lg)`; bump them to 2xl so the
// first tab's start edge lines up under the page title.
[role="tab"] {
padding-inline: var(--wpds-dimension-padding-2xl, 24px);
}
Comment on lines +258 to +260

@ciampo ciampo May 8, 2026 •

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.

Tab's internal padding shouldn't ideally be manually tweaked, since it can diverge from the standard component spacing and can easily cause unexpected changes in the future.

If what you need is to align the first tab, have you tried adding a margin to the tablist, or adding padding to .jp-admin-page-tabs?

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.

Hey @ciampo ! Thanks for taking a look!

Yes, I know we shouldn't be doing this kind of customization. I'm trying to keep all this things wrapped in a central place (AdminPage implements this mixin) which messes with little things that should actually be done upstream. Some are done for speed, others because I see they are already being discussed and some other because there is no real consensus on how to use them.

In this particular case, I don't see any agreement on:

  • do the tabs go inside or outside the Header?
  • if outside (sibling element), does the Header print the border bottom? Tabs use a border bottom, so rendering both looks a bit odd
  • if outside and we want to fix the tabs so they don't scroll with the content, custom CSS is needed
  • if inside, both border bottom overlap, and the tabs one needs to be there as tabs rely on it for consistent active/inactive tab label
  • considering all the above, does tab border bottom goes all the way to the page border? Or does it respect the page content container? On Jetpack the agreement seems to be that the tab "line" (border bottom) reaches the edge of the "page"
  • even with all this, it is expected that the first tab label gets aligned with the Header title/icon, which right now is impossible without a CSS customization

All that said, yes, I could have used the padding on the tabs container rather than on the buttons, I got carried out by the Settings page, where the first tab label is snapped to the border of the page.

Here's a new PR for clean up: #48706

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.

Those could be good questions to ask in WordPress/gutenberg#76709

}

// ── Mobile: admin bar grows to 46px; sidebar goes off-canvas ─────
// Match `.folded` and `.auto-fold` explicitly: both outrank the bare
// `#wpbody-content` selector on specificity, so the media query needs
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

admin-page-layout mixin: style hooks for `@wordpress/ui` Tabs hosted in an AdminPage (sticky `.jp-admin-page-tabs` wrapper, inline-padding alignment for tab buttons, header bottom-border/padding suppression when tabs are present).
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

ToggleControl: forward the `aria-label` prop to the underlying checkbox so consumers can label toggles that have no visible label.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export interface ToggleControlProps {
/** The label for the toggle. */
label?: ReactNode;

/** Accessible name for the underlying checkbox. Use when no visible `label` is rendered. */
'aria-label'?: string;

/** The size of the toggle. */
size?: 'small' | 'normal';

Expand All @@ -37,6 +40,7 @@ const ToggleControl: FC< ToggleControlProps > = ( {
help,
toggling,
label,
'aria-label': ariaLabel,
size = 'normal',
onChange,
} ) => {
Expand Down Expand Up @@ -67,6 +71,7 @@ const ToggleControl: FC< ToggleControlProps > = ( {
disabled={ disabled }
help={ help }
label={ label }
aria-label={ ariaLabel }
onChange={ handleOnChange }
/>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Firewall: add accessible names to the Brute force protection, Block IP addresses, and Trusted IP addresses toggles.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Migrate the Protect admin page tabs from react-router NavLinks to the shared @wordpress/ui Tabs component. No functional change.
1 change: 1 addition & 0 deletions projects/plugins/protect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@wordpress/element": "6.44.0",
"@wordpress/i18n": "6.17.0",
"@wordpress/icons": "12.2.0",
"@wordpress/ui": "0.11.0",
"@wordpress/url": "4.44.0",
"camelize": "1.0.1",
"clsx": "2.1.1",
Expand Down
70 changes: 0 additions & 70 deletions projects/plugins/protect/src/js/components/admin-page/index.jsx

This file was deleted.

This file was deleted.

120 changes: 120 additions & 0 deletions projects/plugins/protect/src/js/components/protect-app/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { AdminPage as JetpackAdminPage } from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { __, sprintf } from '@wordpress/i18n';
import { Tabs } from '@wordpress/ui';
import { useCallback, useEffect, useMemo, useRef } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router';
import useNotices from '../../hooks/use-notices';
import useProtectData from '../../hooks/use-protect-data';
import Notice from '../notice';

/**
* Resolve the active tab value from the current pathname.
*
* Matches '/firewall' and '/settings' exactly or as path prefixes (so future
* nested routes like '/settings/foo' still select the right tab) without
* over-matching unrelated paths like '/firewall-extras'.
*
* @param {string} pathname - The current location pathname.
* @return {string} The active tab value ('scan' | 'firewall' | 'settings').
*/
function getActiveTab( pathname ) {
if ( pathname === '/firewall' || pathname.startsWith( '/firewall/' ) ) {
return 'firewall';
}
if ( pathname === '/settings' || pathname.startsWith( '/settings/' ) ) {
return 'settings';
}
// Default (covers '/scan', '/scan/history', '/scan/history/:filter' and any unmatched path).
return 'scan';
}

const ProtectApp = () => {
const { notice } = useNotices();
const { isRegistered } = useConnection();
const navigate = useNavigate();
const location = useLocation();
const {
counts: {
current: { threats: numThreats },
},
} = useProtectData();

// Redirect to the setup page if the site is not registered.
useEffect( () => {
if ( ! isRegistered ) {
navigate( '/setup' );
}
}, [ isRegistered, navigate ] );

const activeTab = useMemo( () => getActiveTab( location.pathname ), [ location.pathname ] );

// Reset scroll position whenever the active tab changes. The actual scroll
// container is the layout mixin's `overflow: auto` direct child of
// `.admin-ui-page` (a wrapper applied by `<AdminPage>` around `children`),
// not `Tabs.Root` itself. Walk up from Tabs.Root to find that ancestor so
// this stays robust to any future restructuring of `<AdminPage>`.
const tabsRootRef = useRef( null );
useEffect( () => {
let el = tabsRootRef.current?.parentElement;
while ( el && el !== document.body ) {
const { overflowY } = window.getComputedStyle( el );
if ( overflowY === 'auto' || overflowY === 'scroll' ) {
el.scrollTo( { top: 0 } );
break;
}
el = el.parentElement;
}
}, [ activeTab ] );

const onValueChange = useCallback(
value => {
navigate( `/${ value }` );
},
[ navigate ]
);

if ( ! isRegistered ) {
return null;
}

const scanLabel =
numThreats > 0
? sprintf(
// translators: %d is the number of threats found.
__( 'Scan (%d)', 'jetpack-protect' ),
numThreats
)
: __( 'Scan', 'jetpack-protect' );

return (
<JetpackAdminPage
title={ 'Protect' /** "Protect" is a product name, do not translate. */ }
subTitle={ __( 'Automated malware scanning and firewall protection.', 'jetpack-protect' ) }
>
{ notice && <Notice floating={ true } dismissable={ true } { ...notice } /> }
<Tabs.Root ref={ tabsRootRef } value={ activeTab } onValueChange={ onValueChange }>
<div className="jp-admin-page-tabs">
<Tabs.List>
<Tabs.Tab value="scan">{ scanLabel }</Tabs.Tab>
<Tabs.Tab value="firewall">{ __( 'Firewall', 'jetpack-protect' ) }</Tabs.Tab>
<Tabs.Tab value="settings">{ __( 'Settings', 'jetpack-protect' ) }</Tabs.Tab>
</Tabs.List>
</div>
{ /* @wordpress/ui Tabs.Panel unmounts inactive panels by default, so only the
active panel's <Outlet /> mounts and the matched route renders once. */ }
<Tabs.Panel value="scan">
<Outlet />
</Tabs.Panel>
<Tabs.Panel value="firewall">
<Outlet />
</Tabs.Panel>
<Tabs.Panel value="settings">
<Outlet />
</Tabs.Panel>
</Tabs.Root>
</JetpackAdminPage>
);
};

export default ProtectApp;
22 changes: 0 additions & 22 deletions projects/plugins/protect/src/js/components/tabs/index.jsx

This file was deleted.

This file was deleted.

Loading
Loading