Skip to content

Style states: fix state deselection when selecting the already selected block - #81277

Merged
ramonjd merged 1 commit into
trunkfrom
fix/button-state-deselection
Aug 6, 2026
Merged

Style states: fix state deselection when selecting the already selected block#81277
ramonjd merged 1 commit into
trunkfrom
fix/button-state-deselection

Conversation

@talldan

@talldan talldan commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

What?

Fixes #81254, the selected style state was being lost whenever clicking into the already selected block.

How?

The bug was due to an incorrect case in the reducer for the selected style state. The SELECTION_CHANGE action usually dispatches a start.clientId and end.clientId, not just a clientId. The reducer was not handling this.

The code is now updated to preserve the selected state for single block selections if the selected block doesn't change.

Testing Instructions

  1. Add a button block
  2. Open the inspector and select the 'Hover' state
  3. Click the button in the canvas

In trunk: The 'Hover' state becomes deselected
In this PR: The 'Hover' state remains

Screenshots or screencast

Kapture.2026-08-06.at.11.37.10.mp4

Use of AI Tools

OpenCode / Codex

@talldan talldan self-assigned this Aug 6, 2026
@talldan talldan added the [Type] Bug An existing feature does not function as intended label Aug 6, 2026
@talldan
talldan requested a review from ellatrix as a code owner August 6, 2026 10:39
@talldan talldan added [Feature] Style States Related to block style states (currently viewport and pseudo-states) Backport to WP 7.1 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Aug 6, 2026
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Size Change: +17 B (0%)

Total Size: 7.81 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 434 kB +17 B (0%)

compressed-size-action

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

Flaky tests detected in a8ee280.
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/31094135715
📝 Reported tests:

As a user I want to be able to create a navigation overlay for a specific navigation block in /test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('region', { name: /(Editor publish|Save panel)/ }).getByRole('button', { name: 'Save', exact: true })

    at Editor.saveSiteEditorEntities (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/site-editor.ts:45:5)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js:93:4
two users concurrently move list items (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=toolbar[name="Block tools"i]').locator('role=button[name="Move up"i]')
    - locator resolved to <button id=":rq:" type="button" tabindex="-1" aria-label="Move up" data-toolbar-item="true" aria-describedby="block-editor-block-mover-button__description-0" class="components-button block-editor-block-mover-button is-up-button is-next-40px-default-size has-icon">…</button>
  - attempting click action
    - waiting for element to be visible, enabled and stable
    - element is visible, enabled and stable
    - scrolling into view if needed
    - done scrolling
  - element was detached from the DOM, retrying

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:634:7
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:613:3

@ramonjd ramonjd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice, neat fix. Tests well! When I click on the block with the hover state selected the state UI still shows in the inspector.

Everyone gets a video!!

Before

Kapture.2026-08-07.at.09.33.27.mp4

After

Kapture.2026-08-07.at.09.33.42.mp4

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

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.

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

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: i-am-chitti <iamchitti@git.wordpress.org>
Co-authored-by: jordesign <jordesign@git.wordpress.org>

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

@ramonjd
ramonjd merged commit 3e0fe0c into trunk Aug 6, 2026
62 checks passed
@ramonjd
ramonjd deleted the fix/button-state-deselection branch August 6, 2026 23:38
@github-project-automation github-project-automation Bot moved this from 🔎 Needs Review to ✅ Done in WordPress 7.1 Editor Tasks Aug 6, 2026
@github-actions github-actions Bot added this to the Gutenberg 23.8 milestone Aug 6, 2026
@github-actions github-actions Bot removed the Backport to WP 7.1 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Aug 6, 2026
gutenbergplugin pushed a commit that referenced this pull request Aug 6, 2026
…ed block (#81277)

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: i-am-chitti <iamchitti@git.wordpress.org>
Co-authored-by: jordesign <jordesign@git.wordpress.org>
@github-actions github-actions Bot added the Backported to WP Core Pull request that has been successfully merged into WP Core label Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

I just cherry-picked this PR to the wp/7.1 branch to get it included in the next release: e597aa3

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

Labels

Backported to WP Core Pull request that has been successfully merged into WP Core [Feature] Style States Related to block style states (currently viewport and pseudo-states) [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Projects

Development

Successfully merging this pull request may close these issues.

Button block: selecting the button to edit a pseudo-state style returns it to Default state but displays Focused state

3 participants