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

Resize handle jumps around #311

Closed
cloudkite opened this issue Mar 1, 2024 · 7 comments
Closed

Resize handle jumps around #311

cloudkite opened this issue Mar 1, 2024 · 7 comments

Comments

@cloudkite
Copy link

cloudkite commented Mar 1, 2024

Thanks for this amazing library!

Noticed a small bug/weird behaviour that seems to only happen when you have a collapsed panel:

When dragging a resize handle that is to the right of a collapsed panel the resize handle will jump back to its starting drag position when the panel exceeds its maxSize. Would expect it to stop at the maxSize rather than jumping back to the starting position. I think this would be a better user experience as the jump is quite jarring at the moment

https://codesandbox.io/p/sandbox/react-resizable-panels-forked-fsmcvz?file=%2Fsrc%2FApp.js

CleanShot.2024-03-01.at.21.30.50.mp4
@cloudkite cloudkite changed the title Drag handle jumps around Resize handle jumps around Mar 1, 2024
@bvaughn
Copy link
Owner

bvaughn commented Mar 1, 2024

That sandbox link does not work.

Screenshot 2024-03-01 at 10 27 45 AM

@cloudkite
Copy link
Author

Sorry forgot to make it public, should be accessible now.

@bvaughn
Copy link
Owner

bvaughn commented Mar 2, 2024

Got it. Thank you. This is a bug, for sure.

I think the behavior is due to first panel's configuration:

<Panel
  defaultSize={4}
  collapsedSize={4}
  collapsible={true}
  minSize={15}
  maxSize={20}
>

Here is how this library works, at a high level. First, the constraints:

  • Resizing one panel always impacts other panels. (In other words, you can't make one panel so big that it causes another panel to shrink below its minimum size.)
  • Once you've dragged a resize handle past the min/max size of the panel you're resizing, other panels begin to grow/shrink. (I think this feels more intuitive.) For example, notice how dragging the first resize handle resizes the 3rd panel as well:
  • If you reverse drag direction, any resized panels should return toward their original sizes (aka the same resize in reverse)

The above points can be seen with this example group in the video below:

 <PanelGroup direction="horizontal">
   <Panel defaultSize={30} minSize={20}>
     left
   </Panel>
   <PanelResizeHandle />
   <Panel minSize={30}>
     middle
   </Panel>
   <PanelResizeHandle />
   <Panel defaultSize={30} minSize={20}>
     right
   </Panel>
 </PanelGroup>
Kapture.2024-03-02.at.08.16.47.mp4

Okay, so how is the above behavior implemented (particularly the 3rd bullet):

  • When a drag starts, this library stores the starting coordinates and group layouts
  • As the cursor moves, the delta is (re)applied to the starting layout. (This has the benefit of "rewinding" in the exact same way if you reverse the drag.)
  • If a drag delta can't be applied to the group because of min/max constraints (aka if the new sizes don't add up to 100%) the drag is rejected and no change is applied

The third bullet above is what's causing the issue you've reported. There is a certain range of drag that produces an invalid layout because of the first panel's collapsed and minimum size constraints. (Basically that panel stays collapsed until it is greater than ~9.5% width, the mid point between its collapsed size of 4% and its minimum size of 15%.)

I think the problem is that the invalid layout at that delta causes the group to fall back to the original layout (rather than the most recent valid layout). That's kind of an oversight on my part. Having this repro should be enough to help me track it down.

In case it's easier to see this by looking at actual code, I recorded a Replay of this (3ae6f833-4e3b-4ad6-b10b-8392b85b4bb2) with comments showing what I explained above.

@bvaughn
Copy link
Owner

bvaughn commented Mar 2, 2024

I think I've fixed it, but I need to do some more testing (at least write some regression tests)

Kapture.2024-03-02.at.08.43.05.mp4

@bvaughn
Copy link
Owner

bvaughn commented Mar 2, 2024

Fixed in #312 and published as 2.0.12


❤️ → ☕ givebrian.coffee

@bvaughn bvaughn closed this as completed Mar 2, 2024
@cloudkite
Copy link
Author

☕️☕️☕️❤️

@bvaughn
Copy link
Owner

bvaughn commented Mar 2, 2024

Thanks!🙏

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

No branches or pull requests

2 participants