-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Fields: Add MediaEdit component #73537
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
Conversation
|
Size Change: +975 B (+0.04%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
34a6ba0 to
fd68577
Compare
fd68577 to
577a4b8
Compare
|
Flaky tests detected in fb77be9. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/20376422173
|
90fab95 to
9d99182
Compare
|
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. |
| } | ||
| } | ||
|
|
||
| .dataforms-layouts-panel__field-control { |
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.
What do we need to remove these internal DataViews/DataForm classes from here? It's risky to use them (there are not public API and so can break at any moment).
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.
I can check, but noting that these styles were there from before. They are not part of the actual changes.
|
Is the media upload working for you? The new uploads only show up for me after reloading the screen: Screen.Recording.2025-12-18.at.17.54.46.mov |
Hm... Tested in trunk and this seems an issue for the |
fb77be9 to
57c8efc
Compare
That could be quite challenging for a few reasons.
--edit Thinking about it more, maybe we won't need changes in media upload components and re-sort the returned value from the selected values. I'll have to explore in code. It would also need some design (-cc @jameskoster ), and I guess it would be easier to have something similar to the block movers (buttons with icons) and not drag and drop. Screen.Recording.2025-12-22.at.1.24.19.PM.mov |
| setValue: ( { value } ) => ( { | ||
| featured_media: value ? Number( value ) : 0, | ||
| } ), |
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.
Can we absorb this as part of the MediaEdit?
I understand that it already returns a number (so no need to coerce it again). In that link, perhaps the MediaEdit can remove the undefined type and return 0 when we remove the image? would that work?
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.
It seems inline with what we do here
| editPost( { featured_media: 0 } ); |
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.
Actually I updated this because of the feedback here. 0 is specific to featured image setting and not generic, so it should not be part of MediaEdit.
I can remove the extra Number coercion though. It was just a bit defensive programming :)
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.
My concern here is that every consumer needs to add the same.
Why can't we do this in the MediaEdit? As far as I understood, isn't this restriction (0 for no featured media image) part of the how the REST API endpoints work?
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.
As far as I understood, isn't this restriction (0 for no featured media image) part of the how the REST API endpoints work?
I looked at WP REST API, and I can see that it's the approach there; we use 0 as the default value for object ID, like featured media, menu order, parent, or author. So it makes sense for WordPress, and a sensible default, too. But because Data Views should be framework agnostic, I think we need to at least document the behavior of default/empty value here.
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.
We could change the default to zero and document this, but in general we can use this component for updating some post meta that holds an array of ids, where 0 as an empty value doesn't make much sense.
I have no strong opinions and maybe the next usages of this component might dictate what's better to use as default empty value.
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.
So it makes sense for WordPress, and a sensible default, too. But because Data Views should be framework agnostic, I think we need to at least document the behavior of default/empty value here.
The MediaEdit component we created in this PR is WordPress-specific, so I think it's best to absorb it as part of that instead of asking every consumer to add the same setValue.
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.
WordPress-specific doesn't mean necessarily that is featured image specific. The above examples for author, parent etc.. don't apply here and this will probably be used mostly for custom post meta and even more for fields with multiple values, where storing 0 instead of no value doesn't feel natural to me. I'm still not sold about changing to 0 and would appreciate some more opinions.
oandregal
left a comment
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.
API-wise, this is in a good place to land, and we've identified follow ups as well. Thanks for all the work here!
|
I've reopened #72614 and listed there some follow-ups. |
|
Great work here, folks! I'm about to head out the door on AFK so apologies for the drive-by comment (I won't see any replies). It's incredibly minor but I noticed that when focused via keyboard the focus outline and the border on the button is duplicated so it looks a tiny bit unpolished in that context:
Also, I was wondering if the border color should be a bit lighter? It might be clearer when we go to replace the Featured Image button in the post sidebar:
Currently I feel like the button in this PR is styled to look a bit like an input field, but I'm wondering if the styling of the
In any case, all very minor nitpicky stuff and easy to iterate on (and I'd defer to @jameskoster on all this stuff anyway). I mostly wanted to capture the thought before I close the laptop for the year. Nice work again, and excited to see this reusable component taking shape! |



What?
Resolves: #72614
This PR starts the work for adding a reusable
MediaEditcomponent that can be shared from other media fields, in WordPress context in order to handle file management through media library or the GB experimental media library modal powered by DataViews.Designs
Right now I've implemented the 'compact' variant of the component and the expanded one should be implemented in a follow up.

Next steps
fieldspackage.site logo, content only controls etc..imgfor images andiconsfor the rest), but we might want to improve these. It can also be a follow up.Testing Instructions
Data Views: new media modalGB experiment.setValueto something like:This code would allow any file types and also multiple selection. You can test combinations with the above by adding specific
allowedTypesand/or removingmultiple. Noting that the with the above code thesavewon't work properly (unless it's a single image), because we're hijacking thefeatured imagepost's value. It should be enough to test the UI/UX though.Recording
The above snippet for multiple files and multiple allowed file types is used for this video.
Screen.Recording.2025-12-18.at.10.28.59.AM.mov