Make WordPress Core

Opened 3 months ago

Last modified 2 months ago

#64263 new defect (bug)

Backport: Add support for pseudo classes for the block and its variations on theme.json

Reported by: scruffian's profile scruffian Owned by:
Milestone: 7.0 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch has-unit-tests
Focuses: Cc:

Description (last modified by joedolson)

What?

Backport for https://github.com/WordPress/gutenberg/pull/71418

Adds support for pseudo classes 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 classes, so now we can style hover for the outline variation too.

Why?

This is needed ahead of https://github.com/WordPress/gutenberg/issues/38277 since right now we are only supporting pseudo classes 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 classes 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"
						}
					}
				}
			}
		}
	}
}

Screenshots

https://github.com/user-attachments/assets/7e215a0c-f841-4650-b2a0-a2d2f3f4dd49

Change History (4)

This ticket was mentioned in PR #10523 on WordPress/wordpress-develop by @scruffian.


3 months ago
#1

  • Keywords has-unit-tests added

## What?
Closes https://github.com/WordPress/gutenberg/issues/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 https://github.com/WordPress/gutenberg/issues/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"
						}
					}
				}
			}
		}
	}
}

## Screenshots or screencast
https://github.com/user-attachments/assets/7e215a0c-f841-4650-b2a0-a2d2f3f4dd49

Trac ticket: https://core.trac.wordpress.org/ticket/64263#ticket

#2 @joedolson
3 months ago

  • Description modified (diff)
  • Summary changed from Backport: Add support for pseudo elements for the block and its variations on theme.json to Backport: Add support for pseudo classes for the block and its variations on theme.json

@scruffian So this ticket is more clear, I'm correcting the text in this issue from pseudo elements to pseudo classes, since that's what this is actually about.

@poena commented on PR #10523:


3 months ago
#3

Can we update the testing instructions to include changing the element of the button to <button>, using the HTML element option in the Advanced section.

#4 @palak678
2 months ago

I tested this on 6.8.3 locally. Before patch the hover variation was not working. But after applying the patch the variation works. The patch is working for me.

Kindly refer below video for results:-
https://www.awesomescreenshot.com/video/46851070?key=25bbe03508d62f60b11d48165b75ef19

Note: See TracTickets for help on using tickets.