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

[EuiResizableContainer] Resizable container misbehaves when using react-reverse-portal #6199

Closed
davismcphee opened this issue Aug 31, 2022 · 5 comments
Labels

Comments

@davismcphee
Copy link
Contributor

We're using EuiResizableContainer as part of a project to make the histogram in Discover resizable (elastic/kibana#139446). In some cases the resizable layout is swapped out with a fixed layout such as when viewing on small screens or when hiding the histogram. Typically when this happens React has to remount the child components since their parents have changed, but this causes rendering delays as the child components are pretty heavy to remount. To keep the children from remounting when the layout is swapped, we're using the react-reverse-portal library (https://github.com/httptoolkit/react-reverse-portal).

This works as intended except that EuiResizableContainer conflicts with react-reverse-portal. It seems that resizing stops working whenever the mouse leaves the resize button element while dragging:
resizable_reverse_portals

I've created a branch in my EUI fork demonstrating the issue on the EuiResizableContainer docs page: https://github.com/davismcphee/eui/tree/resizable-reverse-portals.

@thompsongl
Copy link
Contributor

thompsongl commented Aug 31, 2022

Hey @davismcphee

I could be misunderstanding, but I'm not sure it has to do with react-reverse-portal.
#4931 reports that when the mouse leaves the resizer, that resizing stops. This is request that we haven't had a chance to take on yet.

@davismcphee
Copy link
Contributor Author

@thompsongl Thanks for the quick response! It looks like the issue you linked relates to what happens when the cursor is moved outside of the EuiResizableContainer while resizing. The issue I'm experiencing is that when using react-reverse-portal the resize is cancelled when the cursor moves outside of the EuiResizableButton even though it's still within the EuiResizableContainer.

Since the button follows the cursor when resizing, moving slowly keeps the cursor above the button and things work as intended. But if you move the cursor slightly faster, the button will naturally lag a bit and the cursor will move from over top it to above the panels. This is when the resizing seems to be cancelled.

@davismcphee
Copy link
Contributor Author

@thompsongl Looking into this further, it seems this is related to event delegation in React and is a known issue with react-reverse-portal: httptoolkit/react-reverse-portal#13. For our Discover use case I was able to work around it by monitoring for when resizing starts and ends, and toggling a transparent overlay above the panels while resizing. The overlay emits the events EuiResizableContainer is listening for and resizing works as expected.

Considering how niche this use case is, I wouldn't expect EUI to implement a similar workaround to support it, but I was wondering if it would make sense for EuiResizableContainer to implement onResizeStart and onResizeEnd callbacks to generically support these types of use cases? Currently my solution is fairly hacky using wrapping divs, etc. with their own event listeners to pull it off.

If this is something the EUI team would be open to, I'll close this issue and open a new one requesting the callbacks instead.

@thompsongl
Copy link
Contributor

thompsongl commented Sep 8, 2022

would make sense for EuiResizableContainer to implement onResizeStart and onResizeEnd callbacks

Ah yes I like that idea!

toggling a transparent overlay above the panels while resizing

This is an interesting idea re: #4931. Augment the UI broaden the drag area.

@davismcphee
Copy link
Contributor Author

Ah yes I like that idea!

Great! I've created an issue for the callbacks instead (#6225), so I'll close this one now.

This is an interesting idea re: #4931. Augment the UI broaden the drag are.

Yup I think this approach would likely work for the charts use case from the issue, and something similar might be possible for extending the drag area by using an overlay with fixed positioning. I'm not sure how this would affect the event listeners though. For reference, this component includes our current workaround: https://github.com/elastic/kibana/blob/75a660174a2bee9b32ef81521331aebe0c83491a/src/plugins/discover/public/application/main/components/layout/discover_panels_resizable.tsx

@davismcphee davismcphee closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants