Skip to content

Cover block: add media editor modal#79258

Merged
ramonjd merged 2 commits into
trunkfrom
try/add-image-editor-modal-cover-block
Jun 18, 2026
Merged

Cover block: add media editor modal#79258
ramonjd merged 2 commits into
trunkfrom
try/add-image-editor-modal-cover-block

Conversation

@ramonjd

@ramonjd ramonjd commented Jun 17, 2026

Copy link
Copy Markdown
Member

What?

Maybe fixes #15696

Adds a Crop toolbar button to the Cover block when it uses an editable image attachment.

The button opens the existing media editor modal, allowing image edits such as crop, rotate, and flip without adding Cover-specific transform controls.

The button is hidden when the Cover block is using a video, embed, featured image, temporary upload/blob URL, content-only mode, or when the media editor modal is unavailable.

Kapture.2026-06-17.at.15.45.41.mp4

Why?

This offers an alternative to adding a custom flip control to the Cover block. Reusing the shared media editor keeps image editing behavior centralized and avoids introducing Cover-specific image transformation UI.

Testing Instructions

  1. Create or edit a post.
  2. Add a Cover block.
  3. Choose an image from the Media Library.
  4. Select the Cover block.
  5. Confirm a Crop button appears in the block toolbar.
  6. Click Crop.
  7. Confirm the media editor modal opens.
  8. Apply an edit, such as flip, rotate, or crop.
  9. Save the edit.
  10. Confirm the Cover block updates to use the edited image.
  11. Add or switch the Cover block to a video or embedded video.
  12. Confirm the Crop button is not shown.

@ramonjd ramonjd self-assigned this Jun 17, 2026
@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Block] Cover Affects the Cover Block - used to display content laid over a background image labels Jun 17, 2026
@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

Size Change: +315 B (0%)

Total Size: 8.6 MB

📦 View Changed
Filename Size Change
build/scripts/block-library/index.min.js 324 kB +315 B (+0.1%)

compressed-size-action

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

Flaky tests detected in 20c97a3.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/27734463835
📝 Reported issues:

@jasmussen

Copy link
Copy Markdown
Contributor

Honestly this looks compelling to me, happy to try it. This is a deduplication of concerns, focusing on a single and good solution. I'm here for it.

@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

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 props-bot label.

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @vonloxx.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: vonloxx.

Co-authored-by: ramonjd <[email protected]>
Co-authored-by: andrewserong <[email protected]>
Co-authored-by: jasmussen <[email protected]>
Co-authored-by: paaljoachim <[email protected]>

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

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

Great idea! In practice this feels really nice to me, and it gives much more control while interacting directly with the cover block, without having to go out to the media library:

2026-06-18.10.51.59.mp4

Just left a comment about the label for the crop, but the other question I had is whether we should recompute the overlay color and isDark? It's a little messy currently in the Cover block code as there's a useEffect for managing it, but it only fires when the featured image setting is enabled, and otherwise the logic exists in the callbacks. IMO not a blocker to landing if it looks like a rabbit hole. The main edge case here is if someone is cropping away really bright or really dark areas of an image that would result in flipping the values 🤔

Overall, though, this looks like a good improvement — it adds useful functionality, but it's also very safe to remove again if it proves confusing for users as it doesn't alter how the Cover block itself works.

<ToolbarButton
ref={ editMediaButtonRef }
icon={ crop }
label={ __( 'Crop' ) }

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.

Because the Cover block isn't just about the background image itself, should we be slightly more specific with the label? I.e. Crop image or Crop background image?

The crop button sits next to the "Full height" button which affects the outer wrapper of the Cover block itself, so it's possible someone might think that they could use the Crop button to change the size of the block itself (where they'd really want to be using width / height controls)

@ramonjd

ramonjd commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

Thanks @andrewserong

The main edge case here is if someone is cropping away really bright or really dark areas of an image that would result in flipping the values

I haven't actually tested this PR a lot yet 😄 just the happy path, so thanks for pointing this stuff out!

Initially, I'd class that as a feature really, but if getMediaColor() is doing some automagic computation then it might be worth triggering it again when the image changes. I'll take a look.

@andrewserong

Copy link
Copy Markdown
Contributor

Initially, I'd class that as a feature really, but if getMediaColor() is doing some automagic computation then it might be worth triggering it again when the image changes. I'll take a look.

It can be a bit tricky these things sometimes as this case is "a media item already exists and a user is performing a crop" so it might wind up being that we want the simpler approach anyway. Again, not a blocker if you reckon it's better to leave it off for now!

@ramonjd

ramonjd commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

It can be a bit tricky these things sometimes as this case is "a media item already exists and a user is performing a crop" so it might wind up being that we want the simpler approach anyway

Good point. I'm not sure which direction to go on this one - if the overlay color changes too much it might be unexpected. I'll have a looksy anyway, but if it works out to be too spaghetti, I'll mark it as a follow up.

…hance media update handling with average background color calculation and overlay color management.
: {} ),
};

if ( newUrl ) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I kept the change targeted to the new media editor update path rather than refactoring the existing Cover media-selection logic. I tried the latter first, but wasn't confident about it affecting existing flows.

Maybe a follow up to unify, but it'd be a behavioral refactor so I'm not sure I'd want to make this PR more complicated.

There's a fair bit going on, e.g., overlay color, isDark, isUserOverlayColor, undo persistence, and sometimes dim ratio so any shared helper could trigger unintended side effects.

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.

Keeping it contained to this flow sounds wise, then 👍

Comment thread packages/block-library/src/cover/edit/block-controls.js

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

Thanks for the updates, this is looking good to me! Stress tested with some artificial images that are made up of solid black and white areas, and after a crop, the dark mode and overlay color is set correctly 👍

2026-06-18.15.25.00.mp4

Not pictured: a user selected overlay color is also preserved as expected.

Only other question I had was whether we should or shouldn't be resetting the focal point, too. We currently don't reset it after updating to the new crop. Because some folks might adjusting flip but not cropping other dimensions, I think I lean slightly toward not mutating that value when a crop occurs, but it's hard to know what a user might expect. For that one, I reckon we could revisit if we find that users are struggling with it.

LGTM, I think this is a nice feature addition 🚀

@ramonjd

ramonjd commented Jun 18, 2026

Copy link
Copy Markdown
Member Author

I think I lean slightly toward not mutating that value when a crop occurs, but it's hard to know what a user might expect

Good question. I thought about it, but decided against it too. It's a user action that requires some effort, so I'd hope it'd be expected that changing the image dimensions will affect the focal point.

And either way: reset or no, the value will have be changed again manually.

I mean, you're right: it's hard to know exactly what's expected here. I guess we'll find out 😄

Thanks again for testing 🙇🏻

@ramonjd ramonjd merged commit 64c7500 into trunk Jun 18, 2026
43 of 46 checks passed
@ramonjd ramonjd deleted the try/add-image-editor-modal-cover-block branch June 18, 2026 05:35
@github-actions github-actions Bot added this to the Gutenberg 23.5 milestone Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Cover Affects the Cover Block - used to display content laid over a background image [Package] Block library /packages/block-library [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cover block: Add flip background horizontally option/attribute

3 participants