Skip to content

Gallery: In a multiselection, hide controls that are unsupported - #87374

Merged
andrewserong merged 3 commits into
trunkfrom
fix/gallery-block-hide-unusable-controls-in-multi-selection
Nov 25, 2026
Merged

andrewserong merged 3 commits into
trunkfrom
fix/gallery-block-hide-unusable-controls-in-multi-selection

Conversation

@andrewserong

@andrewserong andrewserong commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Aspect ratio
  • Resolution
  • Sorting (including random)
  • Link target (open in new window)
  • Detach block control
  • Link block control
  • The whole Source panel (that allows users to toggle between a static and dynamic gallery)

And in resetAll we 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:

  • In a single block selection, double-check that the above controls are all still visible
  • In a multi-selection of two or more galleries, check that the above controls are hidden
An AI-generated exhaustive set of testing instructions (here for reference, no need to follow it)

Setup

  1. Create a post and add two Gallery blocks, each with at least two images. Upload the images in this post, or attach them to it, so you can test dynamic
    Galleries later.
  2. On the first Gallery, set the Link (toolbar) to "Link images to media files", so the "Open images in new tab" setting appears.
  3. If your theme provides aspect ratios (most block themes do, e.g. Twenty Twenty-Five), check that "Aspect ratio" appears in the Settings panel.

Single selection (no change expected)

  1. Select one Gallery.
  2. In the toolbar, check that Link and Add are shown.
  3. In the inspector, check that the Source panel is shown with its "Use attached images" button.
  4. In the Settings panel, check that Columns, Order by, Resolution, Open images in new tab, Aspect ratio and Crop images to fit are shown. Navigation button
    type shows when Link is set to "Enlarge on click".
  5. Change a few settings, then use "Reset all" from the Settings panel menu and check that they all go back to their defaults, as on trunk.

Multi-selection of static Galleries

  1. Select both Galleries, by Shift-clicking or by selecting them in List View.
  2. In the toolbar, check that Link and Add are hidden.
  3. In the inspector, check that the Source panel is hidden.
  4. In the Settings panel, check that Order by, Resolution, Open images in new tab and Aspect ratio are hidden.
  5. Check that Columns and Crop images to fit are still shown, and that changing them updates both Galleries.
  6. Set Link to "Enlarge on click" on both Galleries one at a time, then multi-select them again and check that Navigation button type is shown and changing
    it updates both Galleries.
  7. Set a different number of columns on each Gallery, multi-select them, then use "Reset all". Check that Columns, Crop images to fit and Navigation button
    type are reset. Images, image links, resolution and Random order should stay unchanged.

Multi-selection of dynamic Galleries

  1. Add two more Gallery blocks and use "Use attached images" on each one, from the placeholder or the Source panel.
  2. Select one dynamic Gallery and check that Detach is shown in the toolbar and "Detach Gallery" is shown in the Source panel.
  3. Select both dynamic Galleries and check that Detach is hidden in the toolbar, the Source panel is hidden, and Order by is hidden in the Settings panel.

Mixed static and dynamic Galleries

  1. Select a static Gallery and a dynamic Gallery together. They need to be next to each other.
  2. Check that none of the hidden controls above are shown, whichever Gallery is first in the selection.

Galleries in a grid layout

  1. Switch both Galleries to the "Gallery Grid" variation and make sure Link is not set to "Enlarge on click".
  2. Multi-select them and check that no empty Settings panel is shown in the inspector.

Viewport states (if responsive editing is enabled)

  1. Multi-select two Galleries and switch to a viewport state, such as Mobile.
  2. Check that Columns and Crop images to fit are shown and Aspect ratio is hidden.
  3. Check that "Reset all" clears the Columns and Crop images to fit overrides for the viewport.

Screenshots or screencast

Before After
image image

Use of AI Tools

Claude Code (Opus 5.5)

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

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: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +58 B (0%)

Total Size: 8.71 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 428 kB +58 B (+0.01%)

eec5745 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 42caf96 trunk % Change
timeToFirstByte 56.95 ms +7.46% -3.16% 56.8 ms +5.72% -3.43% 0.26%
largestContentfulPaint 84 ms +7.14% -0% 88 ms +9.09% -4.55% -4.55%
lcpMinusTtfb 29.35 ms +5.62% -4.94% 30 ms +30.67% -6.67% -2.17%
wpBeforeTemplate 29.39 ms +15.28% -1.63% 29.51 ms +8.74% -2.07% -0.41%
wpTemplate 22.99 ms +4% -4.05% 22.64 ms +4.24% -2.92% 1.55%
wpTotal 53.2 ms +7.16% -3.18% 52.79 ms +6.84% -3.01% 0.78%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 42caf96 trunk % Change
timeToFirstByte 47.05 ms +3.93% -2.98% 46.95 ms +5.75% -1.81% 0.21%
largestContentfulPaint 84 ms +0% -4.76% 80 ms +5% -0% 5%
lcpMinusTtfb 35.1 ms +6.7% -2.28% 34.15 ms +2.49% -2.49% 2.78%
wpBeforeTemplate 26.68 ms +9.26% -1.35% 26.64 ms +7.85% -0.64% 0.15%
wpTemplate 16.36 ms +3.97% -2.44% 16.72 ms +2.15% -3.41% -2.15%
wpTotal 43.83 ms +4.31% -3.19% 43.77 ms +6.31% -2.4% 0.14%
wpMemoryUsage 6.44 MB +0% -0% 6.41 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 42caf96 trunk % Change
mediaProcessingJpeg 402.25 ms +0.82% -0.69% 398.93 ms +0.99% -0.25% 0.83%
mediaProcessingAvif 6187.92 ms +0.22% -0.33% 6167.85 ms +0.18% -0.44% 0.33%
mediaProcessingJpegToAvif 4259.56 ms +0.34% -0.37% 4239.35 ms +0.4% -0.12% 0.48%

media-upload

Metric 42caf96 trunk % Change
jpegUploadProcessing 1976.86 ms +4.03% -22.85% 1743.66 ms +13.34% -13.86% 13.37%
pngUploadProcessing 274.44 ms +2.49% -2.38% 269.86 ms +1.98% -1.49% 1.7%
largeJpegUploadProcessing 1764.79 ms +12.64% -14.39% 1953.09 ms +1.57% -22.41% -9.64%
multipleImageUploadProcessing 2064.75 ms +0.46% -0.83% 2089.44 ms +0.27% -1.39% -1.18%

post-editor

Metric 42caf96 trunk % Change
serverResponse 296.87 ms +7.53% -4.06% 320.51 ms +0.8% -9.96% -7.38%
firstPaint 314.35 ms +17.17% -3.07% 321.29 ms +3.5% -3.15% -2.16%
domContentLoaded 633.15 ms +4.11% -1.04% 626.1 ms +3.16% -1.26% 1.13%
loaded 633.89 ms +4.1% -1.01% 626.86 ms +3.15% -1.26% 1.12%
firstContentfulPaint 360.35 ms +7.47% -2.09% 353.02 ms +3.8% -1.07% 2.08%
firstBlock 1697.99 ms +7.8% -1.66% 1685.84 ms +0.64% -0.56% 0.72%
type 13.78 ms +1.52% -8.64% 13.88 ms +4.47% -11.02% -0.72%
typeWithoutInspector 13.72 ms +8.82% -6.78% 13.28 ms +7.68% -5.35% 3.31%
typeWithTopToolbar 17.74 ms +5.07% -7.67% 18.28 ms +3.23% -9.3% -2.95%
typeContainer 6.39 ms +7.98% -9.86% 6.39 ms +1.72% -9.23% 0%
focus 83.37 ms +5.18% -2.54% 80.01 ms +2.94% -3.05% 4.2%
firstFocus 193.88 ms +0% -0% 199.72 ms +0% -0% -2.92%
selectAll 295.51 ms +1.25% -2.18% 289.77 ms +4.03% -1.97% 1.98%
undo 22.74 ms +4.71% -2.46% 23.17 ms +4.57% -4.14% -1.86%
listViewOpen 29.78 ms +7.82% -7.92% 30.62 ms +1.01% -7.18% -2.74%
inserterOpen 31.01 ms +9.48% -5.16% 30.65 ms +11.84% -8.81% 1.17%
inserterHover 9.14 ms +3.61% -9.74% 8.73 ms +5.61% -8.13% 4.7%
inserterSearch 7.01 ms +11.84% -6.28% 6.66 ms +4.5% -1.8% 5.26%
loadPatterns 498.91 ms +1.78% -1.97% 481.55 ms +1.9% -0.54% 3.61%
wpTotal 288.25 ms +7.82% -4.13% 312 ms +0.79% -10.23% -7.61%
wpMemoryUsage 14.80 MB +0% -0% 14.76 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 42caf96 trunk % Change
serverResponse 469.83 ms +1.14% -4.26% 465.44 ms +0.62% -7.69% 0.94%
firstPaint 437.94 ms +6.27% -8.26% 395.17 ms +16.42% -2.8% 10.82%
domContentLoaded 830.69 ms +4.97% -0.77% 828.85 ms +0.63% -0.3% 0.22%
loaded 831.81 ms +4.96% -0.75% 829.87 ms +0.61% -0.27% 0.23%
firstContentfulPaint 467.78 ms +2.78% -3.04% 469.42 ms +0.39% -1.55% -0.35%
firstBlock 2568.14 ms +7.68% -0.94% 2596.72 ms +0.37% -0.8% -1.1%
type 17.05 ms +5.22% -2.11% 19.43 ms +3.45% -6.23% -12.25%
navigate 117.71 ms +6.4% -3.66% 109.34 ms +7.48% -1.94% 7.66%
loadPatterns 1341.84 ms +3.08% -7.85% 1444.93 ms +1.24% -11.96% -7.13%
loadPages 944.24 ms +3.62% -1.69% 957.76 ms +1.54% -1.22% -1.41%
wpTotal 460.3 ms +1.2% -4.31% 456.04 ms +0.58% -7.84% 0.93%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

eec5745 Run

🏁 Flaky tests

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.

Actions are reachable via RIGHT/LEFT arrow keys (Site Editor v2) in /test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator:  getByRole('row', { name: 'Page One View Actions' }).getByLabel('Actions')
Expected: focused
Received: inactive
Timeout:  5000ms

Call log:
  - Expect "toBeFocused" getByRole('row', { name: 'Page One View Actions' }).getByLabel('Actions') with timeout 5000ms
  - waiting for getByRole('row', { name: 'Page One View Actions' }).getByLabel('Actions')
    14 × locator resolved to <button type="button" tabindex="-1" aria-haspopup="menu" aria-label="Actions" aria-expanded="false" id="view-list-0-13-dropdown" class="components-button is-small has-icon">…</button>
       - unexpected value "inactive"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js:181:5
page-list submenu user interactions in /test/e2e/specs/editor/blocks/navigation-frontend-interactivity.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('region', { name: 'Editor top bar' }).getByRole('button', { name: 'Save', exact: true })
    - locator resolved to <button type="button" aria-disabled="true" class="components-button editor-post-publish-button editor-post-publish-button__button is-primary is-compact">Save</button>
  - attempting click action
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
    - waiting 20ms
    2 × waiting for element to be visible, enabled and stable
      - element is not enabled
    - retrying click action
      - waiting 100ms
    16 × waiting for element to be visible, enabled and stable
       - element is not enabled
     - retrying click action
       - waiting 500ms
    - waiting for element to be visible, enabled and stable

    at Editor.saveSiteEditorEntities (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/site-editor.ts:39:22)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/navigation-frontend-interactivity.spec.js:705:4
should give the image its context menu while selected @WebKit @Firefox in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Test timeout of 100000ms exceeded.
should open the welcome guide from the Options menu in /test/e2e/specs/widgets/editing-widgets.spec.js, passed after 2 failed attempts.


eec5745 Run

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Nov 25, 2026
Comment on lines +70 to +94
// 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'
)
);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not going to accuse it of being hacky for sure 😇

@andrewserong
andrewserong marked this pull request as ready for review November 25, 2026 02:02
@andrewserong andrewserong added [Type] Bug An existing feature does not function as intended [Block] Gallery Affects the Gallery Block - used to display groups of images labels Nov 25, 2026
@tellthemachines

Copy link
Copy Markdown
Contributor

Should we hide the list view, given it only shows the blocks for the first gallery in the selection?

Screenshot 2026-11-25 at 1 47 14 pm

I also noticed in testing that with a viewport state enabled, multiple selected Galleries are showing list view and (empty) settings tabs, which they shouldn't:

Screenshot 2026-11-25 at 1 48 55 pm

(to be clear these are issues on trunk and not regressions from your changes; we could address them as follow-ups)

@tellthemachines tellthemachines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry I found another issue 😅

If one of the selected galleries is a grid and the other isn't, it might be better to hide the layout panel. Otherwise configuring grid settings for both galleries can make the non-grid one (bottom one in the screenshot) break:

Screenshot 2026-11-25 at 2 23 38 pm

// 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 😄

@andrewserong

Copy link
Copy Markdown
Contributor Author

Thanks for the eagle eyes here @tellthemachines! I think the remaining issues you've spotted are things to be fixed in block-editor in a separate PR as they're a bit more general purpose fixes than specifically for the Gallery block. (I'm happy to work on those, but might be good to do in a follow-up, I think). So far it sounds like we should:

  • In block-editor hide the List View tab in a multi-selection
  • In block-editor ensure an empty Settings tab doesn't render
  • In block-editor hide the Layout controls in a multi-selection. OR, hide in a multi-selection when not all of the blocks share the same layout type?

What do you reckon?

I've made the comment change, and added another tiny test.

@tellthemachines

Copy link
Copy Markdown
Contributor
  • hide in a multi-selection when not all of the blocks share the same layout type

I think this makes sense! With the same layout type the controls should work well for multi-selections and can be handy to have.

@tellthemachines tellthemachines left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@andrewserong

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews! 🙇

@andrewserong
andrewserong merged commit 4750cbd into trunk Nov 25, 2026
89 checks passed
@andrewserong
andrewserong deleted the fix/gallery-block-hide-unusable-controls-in-multi-selection branch November 25, 2026 04:19
@github-actions github-actions Bot added this to the Gutenberg 24.6 milestone Nov 25, 2026

@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.

A bit late, but since I tested anyway LGTM!

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

Labels

[Block] Gallery Affects the Gallery Block - used to display groups of images [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants