bvaughn / react-resizable-panels

https://react-resizable-panels.vercel.app/
MIT License
3.87k stars 135 forks source link

Missing support for persistence of collapsed panels #234

Closed hubgit closed 9 months ago

hubgit commented 9 months ago

Given that react-resizable-panels supports both collapsible panels and persistence, there are a couple of gaps in support for persistence of collapsible panels that would be useful:

  1. The previous expanded size of a collapsed panel is stored in a ref, so is lost when the page is reloaded. A collapsed panel that's expanded after reloading the page only expands to the defined minimum size, rather than to the previous expanded size. It's possible to work around this by storing the expanded size in localStorage independently, and applying it when the panel is expanded, but it would be useful if the library supported this.
  2. It doesn't seem to be possible to both give a panel a default size and to say that it should be initially collapsed. If you set defaultSize to 0 (so it's initially collapsed) then the panel will only expand to its minimum size. It's possible to work around this by calling collapse() on the panel immediately, but it would be useful if the library supported this, perhaps with an additional prop for the initial collapsed state.
bvaughn commented 9 months ago
  1. The previous expanded size of a collapsed panel is stored in a ref, so is lost when the page is reloaded. A collapsed panel that's expanded after reloading the page only expands to the defined minimum size, rather than to the previous expanded size. It's possible to work around this by storing the expanded size in localStorage independently, and applying it when the panel is expanded, but it would be useful if the library supported this.

I don't think it's a very high priority, but I do think this item could make sense to support.

  1. It doesn't seem to be possible to both give a panel a default size and to say that it should be initially collapsed. If you set defaultSize to 0 (so it's initially collapsed) then the panel will only expand to its minimum size. It's possible to work around this by calling collapse() on the panel immediately, but it would be useful if the library supported this, perhaps with an additional prop for the initial collapsed state.

This item doesn't make sense to me though.

If you want an item's initial size to be collapsed, then having it expand to the minimum size seems reasonable and expected. (If you want it to expand to some other size, you can use the resize(...) API rather than the expand() API.)

If you're talking about a previously rendered panel that was collapsed by the user, then it should be collapsed still after a reload, at which point I think we're really just talking about the first bullet point item above.

I think what you're saying is that you want a panel to be both collapsed by default and expandable by toggle (or expand() API) to some size that's greater than its minimum size. That's not a case I think I should build into this library, because it can be accomplished already with the imperative resize() API.

bvaughn commented 9 months ago

1.0.3 supports the first item you mentioned. The second one should be done in user-space I think.

hubgit commented 9 months ago

Thank you for implementing persistence for the expanded size, that's looking great.

It doesn't seem to be possible to both give a panel a default size and to say that it should be initially collapsed.

If you want an item's initial size to be collapsed, then having it expand to the minimum size seems reasonable and expected.

I think the expectation is that if an item's initial size is collapsed, then it should expand to the default size (or the persisted expanded size, if present). I think of the minimum size only as the point where a panel collapses while dragging to make it smaller.