-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix dropping media from inserter into Cover block #67056
Conversation
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. |
Size Change: +51 B (0%) Total Size: 1.82 MB
ℹ️ View Unchanged
|
@@ -52,23 +52,23 @@ export function attributesFromMedia( media ) { | |||
if ( media.media_type === IMAGE_BACKGROUND_TYPE ) { | |||
mediaType = IMAGE_BACKGROUND_TYPE; | |||
} else { | |||
// only images and videos are accepted so if the media_type is not an image we can assume it is a video. | |||
// Only images and videos are accepted so if the media_type is not an image we can assume it is a video. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work figuring this out!
Dragging and dropping video and image on the cover block work from the media inserter exactly how I'd expect it to.
Tested in Firefox, Chrome and Safari 💯
Kapture.2024-11-18.at.13.55.32.mp4
Optionally, could we tweak the media and text block to allow the same behaviour?
Or could be in a follow up PR if you think that makes sense.
@@ -35,7 +35,7 @@ export function dimRatioToClass( ratio ) { | |||
} | |||
|
|||
export function attributesFromMedia( media ) { | |||
if ( ! media || ! media.url ) { | |||
if ( ! media || ( ! media.url && ! media.src ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we give the media and text block the same treat while we're at it?
if ( ! media || ! media.url ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's a good point! Yeah it would be nice. Media & Text seems to be slightly differently broken though 😅 (trying to drag an image into it actually removes the existing image instead of doing nothing) so I'd rather tackle that as a separate PR.
Flaky tests detected in 660e726. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11883548499
|
What?
Part of #66824.
Fixes a bug observed while working on #66986: dropping Images or Videos from the inserter Media tab into the Cover block media placeholder doesn't add them as background to the Cover block (which would be expected).
One of the issues was the Cover block itself not recognising media from the inserter due to it not having an explicit type. I fixed that by determining the type based on block name in the media placeholder, and appending it to the block attributes.
The other issue was that the Video block uses
src
instead ofurl
, and media placeholder wasn't handing that case. Updated to look forsrc
attributes too.Testing Instructions
Screenshots or screencast
cover-drag.mp4