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

Panels break when changing minSize #142

Closed
bartlangelaan opened this issue May 10, 2023 · 8 comments
Closed

Panels break when changing minSize #142

bartlangelaan opened this issue May 10, 2023 · 8 comments

Comments

@bartlangelaan
Copy link

bartlangelaan commented May 10, 2023

Hey! Thanks for this amazing package :-)

I tried to implement the trick that allows you to set a minSize based on pixels (from your comment #48 (comment)).

However, if I change the minSize, something strange happens. The resize handler starts to work the exact opposite way.

I have made a CodeSandbox example to demonstrate what I mean:
https://codesandbox.io/s/react-resizable-panels-issues-142-vgekmz

Everything works nicely, until the Break! button is clicked. I don't understand how or why.. looks like a bug?

@bvaughn
Copy link
Owner

bvaughn commented May 10, 2023

Give the panels an explicit order prop. (I should probably just make this required)

<PanelGroup direction="horizontal">
  <Panel minSize={minSize} order={0}>
    <Block />
  </Panel>
  <PanelResizeHandle>
    <Block style={{ width: 2, marginLeft: 4, marginRight: 4 }} />
  </PanelResizeHandle>
  <Panel order={1}>
    <Block />
  </Panel>
</PanelGroup>;

https://codesandbox.io/s/react-resizable-panels-issues-142-forked-d164kg

@bartlangelaan
Copy link
Author

bartlangelaan commented May 10, 2023

Hmm, the documentation states that the order prop is only needed if the panels are conditional (which they aren't) or if they have an onResize callback (which they don't)..

Is the order prop like a key? Why is it needed?

@bvaughn
Copy link
Owner

bvaughn commented May 10, 2023

There are other props that- when changed, require a Panel to retegister itself with the PanelGroup- which can cause issues with how the resize handle works (it is associated based on registration order- not visual location on the screen, since there’s no way to know that)

To be clear, this library (at least the docs) could do better here- but for now you can fix the issue you’re reporting by adding an “order” prop

@bvaughn
Copy link
Owner

bvaughn commented May 14, 2023

I think I've made a change that will reduce the likelihood of cases like this. (Basically passing a ref rather than the actual panel– so a panel only needs to register/unregister when it mounts/unmounts.)

bvaughn added a commit that referenced this issue May 14, 2023
Avoid re-registering Panel when props change
@bvaughn
Copy link
Owner

bvaughn commented May 14, 2023

0.0.44 should be better in this regard

@bvaughn bvaughn closed this as completed May 14, 2023
@bartlangelaan
Copy link
Author

Confirmed that the issue doesn't appear with 0.0.44! Thanks!!

@bvaughn
Copy link
Owner

bvaughn commented May 14, 2023

Thanks for confirming! I'm glad to hear it.

@Davenporten
Copy link

Just as additional information: I was having trouble with minSize not working with pixels (I'd set it to a particular value and it would always be much smaller). When I set order the problem was fixed.

Thanks for the great lib!

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

3 participants