Repository navigation
Gallery: In a multiselection, hide controls that are unsupported - #87374
andrewserong merged 3 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the 📦 Bundle sizeSize Change: +58 B (0%) Total Size: 8.71 MB 📦 View Changed
⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome 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. Actions are reachable via RIGHT/LEFT arrow keys (Site Editor v2) in
|
| // Renders a button that selects every Gallery in the editor. The galleries must | ||
| // be next to each other, since a multi-selection is a range of blocks. | ||
| // Selecting from a click rather than on mount keeps the block toolbar from | ||
| // opening while the editor is still being set up. | ||
| function MultiSelectionInitializer() { | ||
| const { getBlockOrder, getBlockName } = useSelect( blockEditorStore ); | ||
| const { multiSelect } = useDispatch( blockEditorStore ); | ||
|
|
||
| function multiSelectGalleries() { | ||
| const clientIds = getBlockOrder().filter( | ||
| ( id ) => getBlockName( id ) === 'core/gallery' | ||
| ); | ||
| multiSelect( clientIds[ 0 ], clientIds[ clientIds.length - 1 ] ); | ||
| } | ||
|
|
||
| return createElement( | ||
| 'div', | ||
| useBlockProps(), | ||
| createElement( | ||
| 'button', | ||
| { type: 'button', onClick: multiSelectGalleries }, | ||
| 'Select galleries' | ||
| ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
This is a similar workaround as we're using above for the viewport state initializer. Happy to go in a different direction if this feels too hacky!
There was a problem hiding this comment.
I'm not going to accuse it of being hacky for sure 😇
| // When several galleries are selected, only the settings stored as gallery | ||
| // attributes are shown. The others also update each gallery's images or | ||
| // inner blocks, which only happens for the first selected gallery. Random | ||
| // order is hidden too, so it's chosen per gallery. |
There was a problem hiding this comment.
This comment isn't making a lot of sense to me. Both aspect ratio and columns are gallery attribs, but columns works across multiple blocks and aspect ratio doesn't. Should we just say something like "hide aspect ratio for multi-selection because it doesn't work across multiple blocks"?
There was a problem hiding this comment.
Yes, we should. Thank you for coming up with some human-readable text here! I sometimes spend far too long on these comments wrestling with the agent, when I should have just written it simply myself 😄
|
Thanks for the eagle eyes here @tellthemachines! I think the remaining issues you've spotted are things to be fixed in
What do you reckon? I've made the comment change, and added another tiny test. |
I think this makes sense! With the same layout type the controls should work well for multi-selections and can be handy to have. |
|
Thanks for the reviews! 🙇 |
ramonjd
left a comment
There was a problem hiding this comment.
A bit late, but since I tested anyway LGTM!



What?
When the gallery block is part of a multi-selection, hide controls that are unsupported.
Why?
Noticed while testing #87334 that the Gallery block currently shows a lot of its settings controls in a multi-selection even though most of those controls are designed to only apply to a single block, and in a multi-selection would only apply to the first Gallery in the selection.
It's much clearer if we only show those features that actually apply across the whole selection. And arguably, adjusting settings is more appropriate for an individual block selection, whereas multi-selection is likely more about applying styling changes. I think.
How?
The approach in this PR is to simply guard those features that are not supported in a multi-selection. If we think that there's a desire or need to make more of these features available in multi-selection, we can explore that in follow-ups. (That's my opinion, anyway!)
The things we're hiding here include:
And in
resetAllwe only reset those properties that could have been set in the multi-selection. This way if someone changes the number of columns across multiple blocks and then resets it, it doesn't clear out aspect ratios, etc, that aren't available in multi-selection.Testing Instructions
Simple version:
An AI-generated exhaustive set of testing instructions (here for reference, no need to follow it)
Setup
Galleries later.
Single selection (no change expected)
type shows when Link is set to "Enlarge on click".
Multi-selection of static Galleries
it updates both Galleries.
type are reset. Images, image links, resolution and Random order should stay unchanged.
Multi-selection of dynamic Galleries
Mixed static and dynamic Galleries
Galleries in a grid layout
Viewport states (if responsive editing is enabled)
Screenshots or screencast
Use of AI Tools
Claude Code (Opus 5.5)