bvaughn / react-resizable-panels

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

How to set a panel collapsed by default? #430

Closed jsartisan closed 6 days ago

jsartisan commented 6 days ago

Is there a way to collapse a panel by default? I am creating this layout: CleanShot 2024-11-13 at 09 02 11 and I want the console panel to be collapsed by default. I don't see any prop that can do it.

bvaughn commented 6 days ago

Just set the default panel size (defaultSize) to the same thing as the collapsed size?

jsartisan commented 6 days ago

Tried this:

const collapsedSize = (100 / parentSize) * 40;

  return (
    <ResizablePanel
      ref={ref}
      collapsible={true}
      minSize={10}
      collapsedSize={collapsedSize}
      defaultSize={props.collapsed ? collapsedSize : undefined}
      {...rest}
    >
      {content}
    </ResizablePanel>
  );

but does not work. When running the above code, the resizing stops working for that group and the size defaults to 50%

jsartisan commented 6 days ago

Let me try again. Most likely i might be messing up some prop. I'll get back.

jsartisan commented 6 days ago

@bvaughn can we define collapsed size in pixels? i remember it was possible around 0.63 version.

My usecase is that i want the collapsed height or width to be 40px.

jsartisan commented 6 days ago

Ok found a way to do it. By using flex-basis to whatever value i want and using collapsedSize and defaultSize as 0

<ResizablePanel
      ref={ref}
      collapsible={true}
      minSize={15}
      defaultSize={props.defaultCollapsed ? 0 : undefined}
      collapsedSize={0}
      className="!basis-10"
      {...rest}
    >
      {content}
 </ResizablePanel>