Skip to content

Components: Clicking on iframe in the content close the modal #40912

Description

@Tropicalista

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

  1. Create a custom component as the one presented here: https://www.tiny.cloud/docs/integrations/react/
  2. Create a simple basic modal and put the component there
  3. Try to type some texts

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

Activity

  1. Tropicalista commented on May 9, 2022

    @Tropicalista
    Author

    The problem is partially solved by adding

    shouldCloseOnClickOutside={ false }

    However some glitch still remaining because cotextual menu need some css because the element are positioned on a lower z-index.

  2. t-hamano commented on May 15, 2022

    @t-hamano
    Contributor

    Hi @Tropicalista,

    I've written test code and was able to reproduce this problem.

    I think the cause may be that onRequestClose is called when the iframe in the modal gets focus.

    Here is the test code.
    I used @tinymce/tinymce-react and dummy iframe content.

    See sample code
    import { 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.mp4

    This might be a problem that should be corrected on the Modal component or useFocusOutside hook.

    Does anyone have a good idea?

  3. added
    [Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.
    on Aug 25, 2022
  4. mrfoxtalbot commented on Sep 19, 2022

    @mrfoxtalbot

    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!

  5. removed
    [Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.
    on Sep 19, 2022
  6. Tropicalista commented on Sep 19, 2022

    @Tropicalista
    Author

    At the moment I use shouldCloseOnClickOutside={ false } and it's working. You can see it in my Formello plugin.

  7. t-hamano commented on Sep 20, 2022

    @t-hamano
    Contributor

    Thank you for the reply, @Tropicalista.
    If so, is it ok to close this issue?

  8. mrfoxtalbot commented on Sep 20, 2022

    @mrfoxtalbot

    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!

  9. github-actions commented on Oct 21, 2022

    @github-actions

    Hi,
    This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps.
    Thanks for helping out.

  10. added
    [Status] StaleGives the original author opportunity to update before closing. Can be reopened as needed.
    on Oct 21, 2022
  11. changed the title [-]It's impossible to type in TinyMce in modal [/-] [+]Components: Clicking on iframe in the content close the modal[/+] on Oct 23, 2022
  12. t-hamano commented on Oct 23, 2022

    @t-hamano
    Contributor

    I've thought about it again, and it may be strange to set shouldCloseOnClickOutside to false to prevent the iframe in the modal content from being closed when clicked, because the iframe is inside the content, not outside it.

    Ideally, I would like to not call onRequestClose when an iframe element in the content is clicked, but I am wondering what implementation would be smart.

    cc @ciampo @mirka

  13. 17 remaining items

  14. ciampo commented on Apr 11, 2023

    @ciampo
    Contributor

    Hey @ivdimova , the problem was not fixed. I had tried an approach with #45349 but (as you can read in the PR description) I didn't make much progress.

    Feel free to work on a solution for this issue and I'll be happy to help with review & advice as necessary

  15. ciampo commented on Apr 11, 2023

    @ciampo
    Contributor

    Tomorrow I can make a PR.

    @stokesman , out of curiosity did you even get to work on this ?

  16. stokesman commented on Apr 12, 2023

    @stokesman
    Contributor

    Yes, I did work on it. Now, the best I can remember is the approach I was trying (fixing it inside useFocusOutside) had some little edge case that kept me from being satisfied with it.

    If @ivdimova is also using the Modal component like in the OP by @Tropicalista, and we want to fix this in the library, it could be worth trying the alternative I'd mentioned above #40912 (comment). To restate it, remove useFocusOutside from Modal and instead utilize its overlay element to catch any outside pointer interaction to trigger the close.

    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 useDialog or useFocusOutside. useConstrainedTabbing must be employed so focus can't otherwise escape.

  17. ciampo commented on Apr 27, 2023

    @ciampo
    Contributor

    It could be worth trying the alternative I'd mentioned above #40912 (comment). To restate it, remove useFocusOutside from Modal and instead utilize its overlay element to catch any outside pointer interaction to trigger the close.

    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.

    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 useDialog or useFocusOutside. useConstrainedTabbing must be employed so focus can't otherwise escape.

    Would it be worth, at this point, revisiting useDialog and embed potentially revised functionality directly in it?

  18. afercia commented on May 22, 2023

    @afercia
    Contributor

    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 onRequestClose prop (which expects a callback to handle the close behavior). That disables the 'close on click outside' behavior but unfortunately disables also the 'close on press the Escape key` behavior. As such, it's not a real solution to the problem and alters the expected behavior of the modal dialog.

  19. ciampo commented on May 23, 2023

    @ciampo
    Contributor

    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!

  20. t-hamano commented on Jun 16, 2023

    @t-hamano
    Contributor

    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 onRequestClose prop, similar to Gutenberg's Modal component. However, clicking on an iframe in a modal does not close the modal. I have not investigated this in detail yet, but this implementation might be a solution.

    03d60681174928d73ebeebe26b54148b.mp4
  21. stokesman commented on Jun 16, 2023

    @stokesman
    Contributor

    @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 Modal also has any overlay element and so the same could be done with it (as I've mentioned previously).

    I've made a PR with that approach and linked this issue to it.

  22. ciampo commented on Sep 1, 2023

    @ciampo
    Contributor

    Hey all, back from some extended AFK.

    I'd like to assess the status of the issue. From what I can see:

    What are your thoughts? (cc @t-hamano @afercia )

  23. stokesman commented on Sep 1, 2023

    @stokesman
    Contributor

    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!

  24. afercia commented on Sep 8, 2023

    @afercia
    Contributor

    @ciampo thanks for the ping. I commented on #51602 (comment)

  25. added
    [Type] BugAn existing feature does not function as intended
    on Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs Technical FeedbackNeeds testing from a developer perspective.[Package] Components/packages/components[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions