react-focus-on icon indicating copy to clipboard operation
react-focus-on copied to clipboard

Working with components portalled to child DOM windows

Open stil opened this issue 1 year ago • 3 comments

Hi, my app is attempting to render components through portals to child windows (opened via window.open).

Directly I use @elastic/eui which uses react-focus-on (and other libraries that you maintain).

I have problems with onClickOutside not firing in my child windows. Are you aware of any compatibility issues that would prevent react-focus-on from working with child windows?

I'm suspecting any hardcoded references to window/document global object such as: https://github.com/theKashey/react-focus-on/blob/7a4752a84257e37c16f300722805f7c0bcd6a26d/src/Effect.tsx#L81-L90

I'm attempting to modify dependent libraries in such way that they inherit current window from Window Provider, similar to https://github.com/microsoft/fluentui/tree/master/packages/react-window-provider

Would it be possible to modify the library in such way so it accepts different window object than the global one?

stil avatar May 22 '24 14:05 stil

FocusLock already uses ownerDocument to refer to the right one, we can try the same approach here.

  • for every shard
  • get an owning document
  • and add event listeners to it
-document.addEventListener('keydown', onKeyDown); 
+activeNode.ownerDocument.addEventListener('keydown', onKeyDown); 

Can you try directly modifying your version of focus-on and share results?

theKashey avatar May 24 '24 01:05 theKashey

Hi, thank you for looking into this issue.

I tried replacing all occurrences of document with activeNode.ownerDocument and it worked! Could you please prepare a release with fix?

stil avatar May 24 '24 08:05 stil

Let's see how it works...

theKashey avatar May 24 '24 21:05 theKashey

This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.

stale[bot] avatar Jul 23 '24 22:07 stale[bot]

This is still valid, please merge the fix from one of the PRs, thank you.

stil avatar Sep 20 '24 23:09 stil