List View block support: Add a private API to allow it to be programmatically toggled#78932
List View block support: Add a private API to allow it to be programmatically toggled#78932andrewserong wants to merge 4 commits into
Conversation
|
Size Change: +223 B (0%) Total Size: 8.2 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in f5278e2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/26991531872
|
|
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. |
|
Switching back to draft while I try out some other ideas. One thing I wasn't quite happy with is that this PR is an imperative call to disable the support. @talldan has suggested looking at a property on I'll be AFK soon, so I'll likely play around with this more sometime next week. |
What?
This is a slightly tentative PR in its implementation, but the idea is:
Add a private per-instance way for a block to disable the List View block support. The idea is that consumers may want/need to be able to disable this programmatically rather than just the boolean in
block.json.I've tried an idea here, but I'm not sure of this approach myself, so would love to hear ideas for how we could achieve this!
Why?
It's possible to have blocks that only want to allow the list tab or view to be available based on a certain set of conditions. The primary use case I have in mind is that of a Dynamic Gallery block that has two modes: a dynamic one where the inner images are fetched via a query, and a static mode where individual blocks are set within the block. I.e what I'm exploring in #78796
That's just one use case, though. There could be many cases where a block wants or needs to hide its internals based on a condition. So this PR is proposing a general way to do that.
How?
setBlockListViewEnabledaction to the block editor packagehasBlockListViewSupportselector to return whether or not the list view support is available — this way we're not just checking if the block type allows it, we're also checking if the block currently supports itFor an example of how a consumer might use this in practice, take a look at #78796 where the gallery block has a
useLayoutEffectthat togglessetBlockListViewEnabledbased on whether the block is in a dynamic state.Testing Instructions
We can simulate the behaviour in #78796 by updating a block locally to switch off the block support. This is quite artificial, the real use case is in the other PR. Here's a diff to apply it to the Gallery block in this branch:
Screenshots or screencast
With the above diff applied for example, the List tab would be hidden:
Use of AI Tools
Claude Code and Codex