Gallery block: Add full align gallery support and unit tests#2587
Gallery block: Add full align gallery support and unit tests#2587mukeshpanchal27 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the Auto Sizes plugin’s Gallery handling so that child core/image blocks inside a full-aligned Gallery inherit alignment behavior (similar to existing wide-alignment support), and it adds unit tests to cover the new behavior and context plumbing.
Changes:
- Treat
core/galleryblocks withalign: "full"as “parent aligned” so childcore/imageblocks can inherit alignment when they don’t explicitly set their own. - Add logic to fall back to default
sizesfor inheritedfullalignment when the gallery image is not effectively full-width (based oncontainer_relative_width). - Add/extend unit tests for full-aligned galleries,
is_parent_alignedrender-block context, andcore/imagecontext usage declarations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| plugins/auto-sizes/includes/improve-calculate-sizes.php | Adds full-aligned Gallery inheritance for child Images and a fallback to default sizes when full alignment shouldn’t apply. |
| plugins/auto-sizes/tests/test-improve-calculate-sizes.php | Adds unit tests for full-aligned gallery scenarios and validates new/required render-block context behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'Full gallery alignment, Default image alignment, 3 images (1 column)' => array( | ||
| 'full', | ||
| '', | ||
| 3, | ||
| 1, | ||
| 'sizes="100vw" ', | ||
| ), | ||
| 'Full gallery alignment, Default image alignment, 4 images (2 columns)' => array( | ||
| 'full', | ||
| '', | ||
| 4, | ||
| 2, | ||
| 'sizes="(max-width: 1024px) 100vw, 1024px" ', | ||
| ), |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix/2449-equal-column #2587 +/- ##
======================================================
Coverage 70.50% 70.50%
======================================================
Files 91 91
Lines 7882 7884 +2
======================================================
+ Hits 5557 5559 +2
Misses 2325 2325
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
plugins/auto-sizes/tests/test-improve-calculate-sizes.php:2177
- In the full-aligned, multi-column gallery case with an incomplete last row (remainder=1), the expected sizes for the last image is
sizes="100vw", which contradicts the intent stated just above (that multi-column full galleries fall back to default sizes, including incomplete rows) and the PR description.
If multi-column full galleries should always use default sizes, the last image here should also use the default sizes string instead of 100vw.
3,
2,
'sizes="(max-width: 1024px) 100vw, 1024px" ',
'sizes="100vw" ',
),
plugins/auto-sizes/includes/improve-calculate-sizes.php:141
- The new early-return for inherited
fullalignment only checkscontainer_relative_width !== 1.0. However, for a multi-column gallery’s incomplete last row whereremainder=1,auto_sizes_filter_render_block_context()setscontainer_relative_widthto1.0for that last image (it uses1.0 / $remainder). This means the last image can still be treated asfulland end up withsizes="100vw", even though the PR description says multi-column full-aligned galleries should fall back to default sizes.
If the intended behavior is “any gallery with column_count > 1 uses default sizes for all images”, consider passing the gallery column count (or a boolean like is_parent_multi_column) through block context to the child Image blocks and using that instead of relying solely on container_relative_width.
$is_parent_gallery_aligned = (bool) ( $block->context['is_parent_aligned'] ?? false );
if ( $is_parent_gallery_aligned && '' === $alignment ) {
$alignment = $max_alignment;
/*
* A full alignment normally spans the whole viewport, but inside a narrower
* container (e.g. a column) the gallery is constrained to that container instead.
* The resulting width cannot be expressed reliably here, so keep the default sizes.
*/
if ( 1.0 !== (float) $container_relative_width && 'full' === $alignment ) {
return $sizes;
|
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. |
Summary
Part of #2449
Treat child Image blocks of a full aligned Gallery as aligned, alongside the existing wide alignment handling. A full aligned gallery only spans the viewport when it has a single column, so multi-column galleries fall back to the default sizes.
Add unit tests covering full aligned galleries with equal and unequal column counts, the 'is_parent_aligned' render block context, and the Image block context declarations.
Use of AI Tools
N/A