-
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
Media library button opens a blank modal when MediaPlaceholder is inside a Popover #39282
Comments
I couldn't reproduce this on WordPress 6.0-alpha-52772 with or without latest Gutenberg from trunk. I'll test on an older install too. First, here's the snippet (can be pasted in devtools console) I used for testing: (({
blocks: { registerBlockType },
blockEditor: { InspectorControls, MediaPlaceholder },
components: { Popover },
element: { createElement: el, Fragment },
}) => {
registerBlockType( 'tester/issue-39282', {
title: 'Test 39282',
edit: () => {
return el( Fragment, null,
el( InspectorControls, {},
el( Popover, { noArrow: false, position: 'middle right' },
el( MediaPlaceholder, {
accept: ['.vtt', 'text/vtt'], onSelect: function (track) {
console.log(track);
} }, "The Media Library button above will fail to render the Media Library modal, rendering a blank modal instead."
)
)
),
el( 'p', {}, 'Inspect me!' ),
);
},
save: () => null,
} );
})(wp); |
I also couldn't reproduce on WordPress 5.8.3 or 5.9.1. What I did see might be an issue though. The popover is above every other popover/modal. Here's a screen capture: test-39282.mp4@mbmjertan, would you test with the snippet I used to confirm it will reproduce the issue for you? It was a conversion of what you posted originally. |
So sorry, the example I provided isn't correct! I've removed the cause by accident 🙈 (I can confirm that my sample, as well as yours, don't reproduce this issue 🤦 ) I originally did this, which was failing. // ...
const [trackEditOpen, setTrackEditOpen] = useState({});
return (
// ...
{trackEditOpen[index] === true &&
<Popover onClose={() => setTrackEditOpen({...trackEditOpen, [index]: false})} noArrow={false} position='middle right'>
<div className='es-popover-content'>
{!videoSubtitleTracks[index].src &&
<MediaPlaceholder
accept={['.vtt', 'text/vtt']}
labels = {{
title: __('Track file', 'eightshift-frontend-libs'),
}}
onSelect={
(track) => {
const modifiedVideoSubtitleTracks = [...videoSubtitleTracks];
modifiedVideoSubtitleTracks[index].src = track.url;
setAttributes({ [getAttrKey('videoSubtitleTracks', attributes, manifest)]: modifiedVideoSubtitleTracks });
}
}
>
{__('Upload a VTT file containing captions, subtitles, descriptions or chapters for this video', 'eightshift-frontend-libs')}
</MediaPlaceholder>
}
{videoSubtitleTracks[index].src &&
<>
<b>{sprintf(__('Track #%d', 'eightshift-frontend-libs'), index + 1)}</b>
</>
}
</div>
</Popover>
}
); It's been possible to reproduce this for me using this code (see full commit in eightshift-frontend-libs) I've tested this out, and the root cause could be that This could very well be expected behaviour, in which case feel free to close this. However, in that case I don't see a way to use |
Thanks @mbmjertan, I've been able to reproduce this now. Snippet used for reproduction:(({
blocks: { registerBlockType },
blockEditor: { InspectorControls, MediaPlaceholder },
components: { Popover, Button },
element: { createElement: el, Fragment, useReducer },
}) => {
registerBlockType( 'tester/issue-39282', {
title: 'Test 39282',
edit: () => {
const [ isOpen, toggleIsOpen ] = useReducer( state => ! state, false );
return el( Fragment, null,
el( InspectorControls, {},
el( Button, { onClick: toggleIsOpen }, 'Toggle Popover' ),
isOpen && el( Popover, { onClose: toggleIsOpen, noArrow: false, position: 'middle right' },
el( MediaPlaceholder, {
accept: ['.vtt', 'text/vtt'], onSelect: function (track) {
console.log(track);
} }, "The Media Library button above will fail to render the Media Library modal, rendering a blank modal instead."
)
)
),
el( 'p', {}, 'Inspect me!' ),
);
},
save: () => null,
} );
})(wp);
.media-modal-backdrop {
z-index: 1000001;
}
.media-modal {
z-index: 1000002;
} |
I can still reproduce the issue, and below is the screenshot of an error I see in the console. Recently @noisysocks implemented a similar UI in #42352. I would recommend checking the code for examples of how to use Screenshot |
Any news? I have the same bug using mediaUpload inside Modal |
I'm getting this error too when i'm trying to open Media libary inside Modal Component. |
use quick fix:
|
I have the same issue and made a workaround by implementing isMediaModalOpen state which is regulated when opening and closing the modal:
then in the popover component, i close the modal only if isMediaModalOpen is false.
Now the media modal is working, however, one issue remains: The popover has a higher z-index then the modal (should it not be the other way around?). The easiest way to fix this was to give the popover a lower z-index value. I have not tested it thoroughly but it seems to work fine. |
This is the same issue as #12830 so closing as a duplicate |
Description
When a
MediaPlaceholder
is nested inside aPopover
component, the Media library button triggers a blank modal instead of the media library.This does not happen when
MediaPlaceholder
is a direct child ofPanelBody
or a block itself.Could be related to #12830
Step-by-step reproduction instructions
I can reproduce by adding this to an
InspectorControls
panel:Screenshots, screen recording, code snippet
A screen recording showing the Media Library button working when in
PanelBody
, and failing when inPopover
:Screen.Recording.2022-03-08.at.11.27.18.mov
Environment info
WP 5.9.1, Gutenberg build shipped with WP.
Reproducible in Firefox 97, Chrome 99, Safari 15.1 on macOS 12.0.1.
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: