Make WordPress Core

Opened 8 months ago

Closed 4 months ago

Last modified 4 months ago

#64838 closed defect (bug) (fixed)

Fix: Block pseudo-state styles incorrectly applied to default state

Reported by: onemaggie Owned by: isabel_brison
Priority: normal Milestone: 7.1
Component: General Version:
Severity: normal Keywords: has-patch has-unit-tests gutenberg-merge
Cc: Focuses:

Description

Backport for ​https://github.com/WordPress/gutenberg/pull/76326/

What?

When a block defines a custom feature selector in its block.json (e.g. core/button uses .wp-block-button for writingMode rather than the root .wp-block-button .wp-block-button__link), styles set on a pseudo-state like :hover via theme.json were being output under the default-state selector instead of the pseudo-state selector.

Why?

This bug will become more apparent when there's a UI to change the state of the button block after ​https://github.com/WordPress/gutenberg/pull/75627 lands.

How?

In get_block_nodes, the metadata node for a block pseudo-state was built with the original $feature_selectors (e.g. .wp-block-button) rather than the pseudo-scoped version (e.g. .wp-block-button:hover). The fix builds a $pseudo_feature_selectors array that appends the pseudo-selector to every feature selector string before the node is created.

A test has been added to catch regressions.

Testing Instructions

Add writing mode to a button block on hover in theme.json, check the frontend and you will see the CSS generated:

Before: :root :where(.wp-block-button) { writing-mode: vertical-rl; }

After: :root :where(.wp-block-button:hover) { writing-mode: vertical-rl; }

The unit tests should all pass too.

Change History (7)

This ticket was mentioned in ​PR #11226 on ​WordPress/wordpress-develop by ​@onemaggie.


8 months ago
#1

  • Keywords has-patch has-unit-tests added

Backport for ​https://github.com/WordPress/gutenberg/pull/76326/
Core trac ticket: https://core.trac.wordpress.org/ticket/64838

## What?

When a block defines a custom feature selector in its block.json (e.g. core/button uses .wp-block-button for writingMode rather than the root .wp-block-button .wp-block-button__link), styles set on a pseudo-state like :hover via theme.json were being output under the default-state selector instead of the pseudo-state selector.

## Why?

This bug will become more apparent when there's a UI to change the state of the button block after ​https://github.com/WordPress/gutenberg/pull/75627 lands.

## How?

In get_block_nodes, the metadata node for a block pseudo-state was built with the original $feature_selectors (e.g. .wp-block-button) rather than the pseudo-scoped version (e.g. .wp-block-button:hover). The fix builds a $pseudo_feature_selectors array that appends the pseudo-selector to every feature selector string before the node is created.

We have added a test to catch this problem should there be a regression

## Testing Instructions

Add writing mode to a button block on hover on theme.json, check the frontend and you will see the CSS generated:

Before:

:root :where(.wp-block-button) { writing-mode: vertical-rl; }

After:

:root :where(.wp-block-button:hover) { writing-mode: vertical-rl; }

The unit tests should all pass too

#2 @wildworks
5 months ago

  • Keywords gutenberg-merge added
  • Milestone Awaiting Review → 7.1

This ticket appears to be targeting 7.1, so I will update the milestone.

​@onemaggie commented on ​PR #11226:


5 months ago
#4

On second though I'll reopen this because the backport is already registered to this ticket and it's worth it keeping the test in

​@onemaggie commented on ​PR #11226:


5 months ago
#5

/cc @tellthemachines if you could have a look?

#6 @isabel_brison
4 months ago

  • Owner set to isabel_brison
  • Resolution → fixed
  • Status new → closed

In 62639:

Editor: ensure no incorrect selector output for pseudo-states.

The output for combined feature selectors and pseudo-states was fixed in [62444] and this removes an extra loop that was outputting an incorrect selector and adds a test.

Props onemaggie, isabel_brison, wildworks.
Fixes #64838.

​@onemaggie commented on ​PR #11226:


4 months ago
#7

@tellthemachines thank you kindly

Note: See TracTickets for help on using tickets.