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

Fixed size panel during container resize #195

Closed
timdown opened this issue Sep 28, 2023 · 7 comments
Closed

Fixed size panel during container resize #195

timdown opened this issue Sep 28, 2023 · 7 comments

Comments

@timdown
Copy link

timdown commented Sep 28, 2023

Thank you for this library. It very nearly does everything needed for the application I'm working on. One thing missing is the ability to have a panel whose absolute size does not change when its container is resized. VS Code's side bar is a good example of this, as illustrated in #114. The requirement is:

  • The panel should stay the same size when its container is resized. Other panels in the group should adjust to fill the remaining space
  • The panel should otherwise be resizable via a resizer in the usual way

I've tried to do this using a ResizeObserver, getSize and resize; it pretty much works but the resizer wobbles a bit as you resize, and it feels dirty given that the library also has a ResizeObserver doing a similar job. I'd make an example on CodeSandbox but its latest version of the library is 0.0.37. This is the kind of thing I tried:

function FixedPanelExample() {
  const fixedPanelRef = useRef<ImperativePanelHandle>(null)
  const fixedPanelPixelWidthRef = useRef(0)

  function updateFixedPanelWidthRef() {
    fixedPanelPixelWidthRef.current =
      fixedPanelRef.current?.getSize('pixels') || 0
  }

  useLayoutEffect(() => {
    updateFixedPanelWidthRef()

    const groupElement = document.querySelector(
      `[data-panel-group-id="fixedPanelGroup"]`
    )
    if (!groupElement) return

    const resizeObserver = new ResizeObserver(() => {
      fixedPanelRef.current?.resize(fixedPanelPixelWidthRef.current, 'pixels')
    })

    resizeObserver.observe(groupElement)

    return () => resizeObserver.unobserve(groupElement)
  }, [])

  return (
    <PanelGroup id="fixedPanelGroup" direction="horizontal">
      <Panel
        id="fixedPanel"
        ref={fixedPanelRef}
        defaultSize={20}
        collapsible
        onResize={updateFixedPanelWidthRef}
      >
        Fixed under container resize
      </Panel>
      <PanelResizeHandle style={{ backgroundColor: 'black', width: '10px' }} />
      <Panel collapsible>Fluid</Panel>
    </PanelGroup>
  )
}

Could a better implementation be added to the library or is there a better way to do this now?

@bvaughn
Copy link
Owner

bvaughn commented Sep 28, 2023

This doesn't sound like a use case I want to support. It sounds pretty niche (and I think supporting it in the library would be pretty complicated). Good luck though!

@bvaughn bvaughn closed this as completed Sep 28, 2023
@timdown
Copy link
Author

timdown commented Sep 28, 2023

Fair enough. I am surprised it's niche, because it's precisely what VS Code does, but the lack of other requests for this suggests you're right.

@bvaughn
Copy link
Owner

bvaughn commented Sep 28, 2023

That's true! First time I've heard of it though. :)

@city17
Copy link

city17 commented Dec 1, 2023

I'm looking for the exact same functionality, would be great if this were possible.

@bvaughn
Copy link
Owner

bvaughn commented Dec 1, 2023

This is not a feature I have any plans to support. (Not saying it's unreasonable, just that I don't have time/energy to support it.)

@pkelaita
Copy link

pkelaita commented Sep 4, 2024

I'm surprised this is niche as well! I've been looking for a way to do this for a collapsable sidebar. Any chance plans to support this have changed?

@bvaughn
Copy link
Owner

bvaughn commented Sep 4, 2024

Nope. Not a use case I’ve ever had.

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

4 participants