Fix: ensure useOnClickOutside
hook correctly detects clicks across iframed editor boundaries
#327
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theuseOnClickOutside
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
Credits
Props @fabiankaegy @ncoetzer
Checklist: