Skip to content

Conversation

@MaggieCabrera
Copy link
Contributor

@MaggieCabrera MaggieCabrera commented Aug 29, 2025

What?

Closes #55359

Adds support for pseudo elements on the core/button block for ( ':hover', ':focus', ':focus-visible', ':active' ) at the theme.json level. This is also allowing the block's variations to control the same pseudo elements, so now we can style hover for the outline variation too.

Why?

This is needed ahead of #38277 since right now we are only supporting pseudo elements on links and button elements, we also want to support them at the block level. This PR brings them in alignment and opens the door to support things like :hover for other blocks that don't have an element (like group for example)

How?

By allowing the pseudo elements for the specific blocks in VALID_BLOCK_PSEUDO_SELECTORS, in a similar way we do for elements.

Testing Instructions

Add the following to your theme and check that it behaves as expected on the frontend:

"styles": {	"blocks": {	"core/button": {	"color": {	"background": "blue"	},	":hover": {	"color": {	"background": "green"	}	},	":focus": {	"color": {	"background": "purple"	}	},	"variations": {	"outline": {	":hover": {	"color": {	"background": "pink"	}	}	}	}	}	} } 

Testing Instructions for Keyboard

Screenshots or screencast

Screen Capture on 2025-09-05 at 11-51-00

@github-actions
Copy link

github-actions bot commented Aug 29, 2025

Flaky tests detected in af55dd7.
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/17399082575
📝 Reported issues:

@MaggieCabrera MaggieCabrera changed the title WIP: getting pseudo elements support for blocks [Button Block]: add support for pseudo elements for the block and its variations on theme.json Sep 5, 2025
@MaggieCabrera MaggieCabrera added [Type] Enhancement A suggestion for improvement. [Block] Buttons Affects the Buttons Block labels Sep 5, 2025
@MaggieCabrera MaggieCabrera marked this pull request as ready for review September 5, 2025 09:57
@github-actions
Copy link

github-actions bot commented Sep 5, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @pablost88, @WinsleyJ.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: pablost88, WinsleyJ. Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: scruffian <scruffian@git.wordpress.org> Co-authored-by: mikachan <mikachan@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: masteradhoc <masteradhoc@git.wordpress.org> Co-authored-by: philhoyt <philhoyt@git.wordpress.org> Co-authored-by: Zealth57 <elrae@git.wordpress.org> Co-authored-by: joemcgill <joemcgill@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: richtabor <richtabor@git.wordpress.org> 

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@MaggieCabrera
Copy link
Contributor Author

@jasmussen I'm going on sabbatical before this is going to land, but maybe we can figure out a UI for this even if we iterate on it later? I think it would be a big win, as you know there's been a lot of feedback asking for this feature over at #38277

@jasmussen
Copy link
Contributor

I'll put it on my radar! Enjoy the break.

@scruffian scruffian force-pushed the try-pseudoelements-blocks branch from af55dd7 to 37cb2fc Compare November 17, 2025 09:30
Copy link
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working well! I've left a few small suggestions.

$style_variation_declarations[ $style_variation['selector'] ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json );

// Process pseudo-selectors for this variation (e.g., :hover, :focus)
$block_name = isset( $block_metadata['name'] ) ? $block_metadata['name'] : ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ? $block_metadata['path'][2] : null );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're extracting the block name in three different places (line 2994, 3028, and 3070. Maybe we could move this to a helper function so it's extracted consistently in each place?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 005f04e

Co-authored-by: Sarah Norris <1645628+mikachan@users.noreply.github.com>
scruffian and others added 5 commits November 20, 2025 08:21
Co-authored-by: Sarah Norris <1645628+mikachan@users.noreply.github.com>
Co-authored-by: Sarah Norris <1645628+mikachan@users.noreply.github.com>
Co-authored-by: Sarah Norris <1645628+mikachan@users.noreply.github.com>
Co-authored-by: Sarah Norris <1645628+mikachan@users.noreply.github.com>
Copy link
Contributor

@scruffian scruffian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@scruffian scruffian enabled auto-merge (squash) November 20, 2025 08:33
@scruffian scruffian merged commit a203fa4 into trunk Nov 20, 2025
34 checks passed
@scruffian scruffian deleted the try-pseudoelements-blocks branch November 20, 2025 11:38
@github-actions github-actions bot added this to the Gutenberg 22.2 milestone Nov 20, 2025
@iamtakashi
Copy link

Nice! Thank you for working on this. I can remove another CSS :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Buttons Affects the Buttons Block [Type] Enhancement A suggestion for improvement.

6 participants