Block visibility: deselect hidden block when list view is not open#76300
Block visibility: deselect hidden block when list view is not open#76300
Conversation
|
Size Change: +134 B (0%) Total Size: 7.75 MB 📦 View Changed
ℹ️ View Unchanged
|
c383e86 to
c910831
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses an editor UX edge case where switching viewport preview can leave a now-hidden block selected (when List View is closed). It centralizes the “effective viewport” resolution logic and adds unit tests to cover both viewport resolution and the preview dropdown’s deselection behavior.
Changes:
- Add
resolveCurrentViewporthelper for consistent viewport resolution (based on device preview + breakpoint fallbacks). - Clear selected block on viewport switch when List View is closed and the selected block becomes hidden in the target viewport.
- Add unit tests for
resolveCurrentViewportand for preview dropdown deselection behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/editor/src/components/preview-dropdown/index.js | Adds deselection logic on viewport switch (conditional on List View state + block hidden status). |
| packages/editor/src/components/preview-dropdown/test/index.js | Adds unit coverage for deselection vs. List View open/closed behavior. |
| packages/block-editor/src/private-apis.js | Exposes resolveCurrentViewport via block-editor private APIs. |
| packages/block-editor/src/components/block-visibility/use-block-visibility.js | Refactors viewport resolution to use shared resolveCurrentViewport. |
| packages/block-editor/src/components/block-visibility/resolve-current-viewport.js | Introduces shared viewport resolution helper. |
| packages/block-editor/src/components/block-visibility/test/resolve-current-viewport.js | Adds unit coverage for viewport resolution helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…wport - Introduced pageUtils to facilitate key presses in the block hiding test. - Added functionality to open List View before switching to mobile preview to maintain block selection when hidden. - Included a comment referencing the related GitHub issue for clarity.
| return BLOCK_VISIBILITY_VIEWPORTS.tablet.key; | ||
| } | ||
|
|
||
| return BLOCK_VISIBILITY_VIEWPORTS.desktop.key; |
There was a problem hiding this comment.
While testing this I found a couple of instances of BLOCK_VISIBILITY_VIEWPORTS.desktop.value (value was the old property)
Fix:
|
Flaky tests detected in 49d856a. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24494411719
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
What?
Testing something out for #76275
This PR:
resolveCurrentViewport.Test Steps
Before
Kapture.2026-04-16.at.15.07.38.mp4
After
Kapture.2026-04-16.at.15.06.12.mp4