-
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
MediaUpload selection results in white screen when launched from a Modal. #12830
Comments
I am experiencing the same issue. My case however is inside . If I move the MediaUpload code to outside the Dropdown it works. Inside Dropdown I get a blank screen on image select or upload. It seems whenever MediaUpload is used inside other components it breaks. There are no javascript console errors. The HTML output is empty for the media modal.
|
Same here when MediaUpload is inside Dropdown. |
Me too, I have the exact same problem as @shamsoft’s |
I think I know what's amiss (even though I have no idea on how to fix it). When I click on the MediaUpload, I'm actually clicking outside the Dropdown, which closes the Dropdown and, therefore, destroys the MediaUpload... or something like that. |
I can confirm what @davilera mentions having noticed similar before. It's this bit of code that does that: gutenberg/packages/media-utils/src/components/media-upload/index.js Lines 346 to 348 in 5d7bd8b
A way to stop it would be to stop the modal behind the uploader from closing. It might be possible to check whether the event that triggers closing happened inside the media uploader and then avoid closing the modal if that's the case. The callback passed to So hopefully it's possible to do something like this would work: onRequestClose={ ( event ) => {
if ( event.target.closest( '.media-frame' ) ) {
return;
}
// else close the modal
} } Though note that For dropdowns/popovers I'm not sure if there's something similar. |
Facing the same issue, any update? |
Thanks to this for the solution: WordPress/gutenberg#12830 (comment)
Can confirm I'm seeing the same issue. Would love to see this resolved in core! |
Revisiting this, I think the main issue is that the <MediaUpload
onSelect={media => console.log ('selected ' + media.length)}
render={({open}) => (
<Button onClick={open}>
Open Media Library
</Button>
)}
/> Having to render the opener button in a render callback is the problem. That forces you to render If it worked like a regular edit: withState ({
isOpen: false,
isMediaLibraryOpen: false,
mediaId: null,
}) (({isOpen, mediaId, setState}) => {
return (
<div>
<Button isDefault onClick={() => setState ({isOpen: true})}>
Open Modal
</Button>
{isOpen
? <Modal
title="This is my modal"
onRequestClose={() => setState ({isOpen: false})}
>
<MediaUploadCheck>
<Button onClick={() => setState({isMediaLibraryOpen: true })}>
Open Media Library
</Button>
</MediaUploadCheck>
</Modal>
: null}
{ isMediaLibraryOpen &&
<MediaUpload
onSelect={media => console.log ('selected ' + media.length)}
/>
}
</div>
);
}) That said, I think anyone reading can implement the steps mentioned in this comment or in my previous comment to work around it, though on that other issue it was mentioned there might also be z-index problems. I think there's a question over how much value there is in solving this one this given a media library rework is on the cards in the very near future - #55238. Though there may be a requirement to make |
Describe the bug
If you use Modal and have a MediaUpload component popup, when you select the image, the component goes blank (all white) and both modals are not recoverable.
To Reproduce
Steps to reproduce the behavior:
edit
:Expected behavior
It should not show a white screen in the modal when the image is selected.
Screenshots
Desktop (please complete the following information):
Additional context
Gutenberg version with WP 5.0
The text was updated successfully, but these errors were encountered: