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

Working with components portalled to child DOM windows #88

Open
stil opened this issue May 22, 2024 · 3 comments
Open

Working with components portalled to child DOM windows #88

stil opened this issue May 22, 2024 · 3 comments
Assignees

Comments

@stil
Copy link

stil commented May 22, 2024

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:

document.addEventListener('keydown', onKeyDown);
document.addEventListener('mousedown', onMouseDown);
document.addEventListener('touchstart', onTouchStart);
document.addEventListener('touchend', onTouchEnd);
return () => {
document.removeEventListener('keydown', onKeyDown);
document.removeEventListener('mousedown', onMouseDown);
document.removeEventListener('touchstart', onTouchStart);
document.removeEventListener('touchend', onTouchEnd);

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?

@theKashey
Copy link
Owner

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 theKashey self-assigned this May 24, 2024
@stil
Copy link
Author

stil commented May 24, 2024

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?

@theKashey
Copy link
Owner

Let's see how it works...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants