Skip to content
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

Fix: ensure useOnClickOutside hook correctly detects clicks across iframed editor boundaries #327

Conversation

fabiankaegy
Copy link
Member

Description of the Change

Update the useOnClickOutside hook to ensure it correctly detects clicks that happen outside / inside the iframed block editor.

This fixes an issue in the Link component that @ncoetzer identified. When the Link component is rendered in a block inside the editor iframe, the link popover didn't properly close when the user clicked outside the element.

The cause for this was that the editor canvas iframe only actually contains the block content. Any additional UI elements such as the <Popover> component get rendered using portals outside of the iframe again. This lead the useOnClickOutside hook to not detect those changes properly and therefore not trigger the callback that should close the popover.

This has been fixed by adding additional listeners that also listen inside / outside the iframe depending on where the element is getting rendered.

Closes #

How to test the Change

Changelog Entry

Fixed - Link Control popover didn't close when rendered inside an iFramed editor.

Credits

Props @fabiankaegy @ncoetzer

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Copy link

github-actions bot commented Jun 7, 2024

Size Change: +393 B (+0.6%)

Total Size: 65.5 kB

Filename Size Change
dist/index.js 65.5 kB +393 B (+0.6%)

compressed-size-action

Copy link
Contributor

@ncoetzer ncoetzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiankaegy LGTM 🚀 Thank you for looking into this.

Copy link
Member

@Antonio-Laguna Antonio-Laguna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabiankaegy this LGTM!

I'd add a comment to make clear this is ONLY applicable within WordPress. You could be tempted if you had a shared codebase to use this elsewhere but it's not ready for that

@fabiankaegy fabiankaegy merged commit a6464a2 into develop Jun 7, 2024
5 of 6 checks passed
@fabiankaegy fabiankaegy deleted the fix/use-on-click-outside-hook-to-work-across-iframed-editor-boundaries branch June 7, 2024 13:37
@cypress cypress bot mentioned this pull request Jun 7, 2024
4 tasks
fabiankaegy added a commit that referenced this pull request Jun 10, 2024
…rk-across-iframed-editor-boundaries

Fix: ensure `useOnClickOutside` hook correctly detects clicks across iframed editor boundaries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Link [Type] Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants