-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Components: Clicking on iframe in the content close the modal #40912
Comments
The problem is partially solved by adding
However some glitch still remaining because cotextual menu need some css because the element are positioned on a lower z-index. |
Hi @Tropicalista, I've written test code and was able to reproduce this problem. I think the cause may be that Here is the test code. See sample codeimport { useBlockProps } from '@wordpress/block-editor';
import { Modal, Button } from '@wordpress/components';
import { useState } from '@wordpress/element';
import { registerBlockType } from '@wordpress/blocks';
import { Editor } from '@tinymce/tinymce-react';
registerBlockType( 'create-block/modal-editor', {
edit: () => {
const [ isOpen, setIsOpen ] = useState( false );
return (
<div { ...useBlockProps() }>
<Button
onClick={ () => setIsOpen( ! isOpen ) }
variant="primary"
>
Toggle Modal Editor
</Button>
{ isOpen && (
<Modal
onRequestClose={ () => {
setIsOpen( false );
console.log( 'modal closed.' );
}}
>
<h2>React Tiny MCE</h2>
<Editor />
<h2>Iframe contents</h2>
<iframe height="250" src="https://github.com/WordPress/gutenberg"></iframe>
</Modal>
)
}
</div>
);
},
save: () => null,
} ); b4940356ef8e64c108a199fcc0590c93.mp4This might be a problem that should be corrected on the Does anyone have a good idea? |
Thank you for reporting this @Tropicalista. Do you have any suggestions on how this could be fixed so we can discuss them and move the issue forward? Thank you! |
At the moment I use |
Thank you for the reply, @Tropicalista. |
If this is still reproducible, we should consider submitting a PR rather than closing the issue, so that this is fixed for everyone. I would love to do this myself but the issue is beyond my technical expertise. @Tropicalista, @t-hamano, would you consider submitting a PR to fix this? Thank you! |
Hi, |
I've thought about it again, and it may be strange to set Ideally, I would like to not call |
Best way to move forward would be to open a PR containing the code to reproduce the issue — that way, we could look at debugging the problem and understand why the modal is closing. |
I suppose it's a z-index problem |
Possibly — but to be sure, I'd have to be able to inspect the code reproducing the issue. Would you be able to open a PR? You could add a temporary Storybook example to |
I have added the test code to the modal component Storybook. The branch is modal-click-iframe. ccac29ff9d1975427ddf0e5e01ef1bd9.mp4 |
Thank you @t-hamano ! I looked into the example, and I think that the issue is caused by this check in gutenberg/packages/compose/src/hooks/use-focus-outside/index.js Lines 162 to 169 in a4af9b3
Basically, clicking on the I will open a PR with a tentative fix. |
Spoke too soon — I've spent some time trying to come up with a good fix, but it's more complicated than I expected. Detecting reliably when a click causing the wrapper to I unfortunately don't have much capacity to work on it. Feel free to try your own attempt (I will still try to push some improvements to the hook that I made while working on this) |
I think this wasn't meant to be linked and closed by #45317 so I'll reopen it.
👆💯 And even when you do that's only half the battle. I think I've been able to find a pretty robust solution but it relies on polling 🥴. As an alternative, a simple fix for |
Curious to take a look if/when the PR(s) are ready for a review! |
While working on other tasks, I came across the I may try to see if I can use it in #45349 as well |
Thanks Marco! I didn't see how that hook could be used directly since it would be consumers that need to put it on their iframes. I did see how I could steal its concept though to avoid the polling that I'd mentioned before. I've tested it out bit but I'm calling it day. Tomorrow I can make a PR. |
I was mainly thinking of asking consumers in need of using an But first, I would have tried it in my tests to see what else would be needed for the whole thing to keep working as expected. Sorry if I didn't explain myself clearly in the previous message! |
I am working on a something similar to @Tropicalista and wondering if this problem was ever fixed? Even if I use |
@stokesman , out of curiosity did you even get to work on this ? |
Yes, I did work on it. Now, the best I can remember is the approach I was trying (fixing it inside If @ivdimova is also using the If Ivelina is making a custom dialog/modal (or wants to try it to avoid waiting on a fix) the same approach should work. I.e. use an overlay element to trigger closing and don't rely on |
I don't currently have the capacity to work on this firsthand, but I'd happy to collaborate and help folks with advice and PR reviews.
Would it be worth, at this point, revisiting |
I was not aware of this issue and created a similar one at #50436 Worth mentioning this problem is now even more important because the Classic block now opens in a modal dialog. The TinyMCE editable area within the modal dialog is in an iframe. The specific problem for this block was worked around by not passing the |
Thank you for the comment, @afercia ! As you can read above, we've been discussing possible solutions, but we haven't landed on one (or haven't found the time to work on it) just yet — feel free to open a PR in case you have an approach in mind, I'll be more than happy to collaborate on it! |
I have created a sample using react-modal to explore the ideal solution to this problem. Code Sandbox: https://codesandbox.io/s/vigorous-carson-6grq7f?file=/src/index.js This library has 03d60681174928d73ebeebe26b54148b.mp4 |
@t-hamano From a brief look at that library and your sample, the reason it works is because it utilizes a click handler on the overlay element. Gutenberg’s I've made a PR with that approach and linked this issue to it. |
Hey all, back from some extended AFK. I'd like to assess the status of the issue. From what I can see:
|
I'm pretty sure this is still present. Neither of the Modal PRs I merged were meant to affect it. Hope you had a great time AFK Marco! |
@ciampo thanks for the ping. I commented on #51602 (comment) |
Description
I'm trying to load a tinymce editor in a gutenberg modal. I'm using the oficial component: https://github.com/tinymce/tinymce-react#readme
The component load correctly the editor, however clicking or typing something will close the modal.
Step-by-step reproduction instructions
Screenshots, screen recording, code snippet
No response
Environment info
No response
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: