Skip to content

Block Style States: Add @current custom state for Nav Link#78769

Draft
MaggieCabrera wants to merge 7 commits into
trunkfrom
add/nav-link-current-style-state
Draft

Block Style States: Add @current custom state for Nav Link#78769
MaggieCabrera wants to merge 7 commits into
trunkfrom
add/nav-link-current-style-state

Conversation

@MaggieCabrera

@MaggieCabrera MaggieCabrera commented May 28, 2026

Copy link
Copy Markdown
Contributor

What?

Closes #38277. Part of #77817.

Adds the @current state to Block Style States so a user can style the active menu item for core/navigation-link, in the block inspector and in Global Styles. Third state axis after pseudo (#76491) and responsive (#78384), and the first custom (class-based) state to ship.

Why?

Until now, theming the current menu item meant hand-writing theme.json or custom CSS. @current is the canonical use case for a class-based state, WordPress applies .current-menu-item at render time when a link's URL matches the request.

How?

  • selectors.states["@current"] on navigation-link/block.json is a class fragment (.current-menu-item), not a full selector. Both consumers compose it under the block's root selector via append_to_selector().
  • Adds an "Item" group to the State dropdown alongside Viewport and Pseudo state; wires the new field end-to-end through the store, path-builder, block inspector, and Global Styles screen.
  • Extracts StateMenuGroup so the three dropdown groups share one source of truth.

Selector shape (kept-on-purpose tradeoff, #75736)

The team split on @current's CSS shape: @scruffian preferred the broad .wp-block-navigation .current-menu-item; @talldan preferred the narrow .wp-block-navigation-link.current-menu-item. This PR lands on talldan's form. Side effect: the Global Styles output shape for @current changes. Needs Dev Note.

Not in this PR

  • Nav Link color/border/spacing supports — separate branch add/nav-link-style-supports. Until that lands, only typography is visible under @current in the block inspector. Global Styles is unaffected (it exposes the full panel).
  • JSON schema docs for selectors.states — follow-up.
  • Public block.json opt-in for third-party blocks — still deferred per Update state support to use config instead of block supports #78088.

Testing Instructions

  1. Open the site editor → Styles → Blocks → Custom Link.
  2. Open the States dropdown in the header → Item → Current.
  3. Set any supported style (e.g. Typography → Font size → Large).
  4. Save Global Styles.
  5. Publish a Page with a Navigation block whose Custom Link points to the Page itself; visit the Page. The current menu item renders the styled rule.

Screenshots

States dropdown on Global Styles:

01-global-styles-state-dropdown 02-global-styles-current-selected 03-global-styles-typography-set

Frontend:

04-frontend-current-menu-item

Use of AI Tools

Authored with Claude Code (Opus 4.7). All output reviewed and validated by the author.

@github-actions github-actions Bot added [Package] Block library /packages/block-library [Package] Block editor /packages/block-editor labels May 28, 2026
@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

Size Change: +801 B (+0.01%)

Total Size: 8.44 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 381 kB +680 B (+0.18%)
build/scripts/block-library/index.min.js 324 kB -4 B (0%)
build/scripts/edit-site/index.min.js 296 kB +47 B (+0.02%)
build/scripts/editor/index.min.js 466 kB +78 B (+0.02%)

compressed-size-action

@MaggieCabrera MaggieCabrera force-pushed the add/nav-link-current-style-state branch from 9e53351 to 80ad5da Compare May 28, 2026 10:25
@github-actions github-actions Bot removed the [Package] Block library /packages/block-library label May 28, 2026
@github-actions

github-actions Bot commented May 28, 2026

Copy link
Copy Markdown

Flaky tests detected in 4223a4b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27193382063
📝 Reported issues:

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Block library /packages/block-library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardized way to modify interactive states (:hover, :focus .etc) for blocks

1 participant