react-split-pane icon indicating copy to clipboard operation
react-split-pane copied to clipboard

Resizer bar not auto adapt to window size if user manual changed the splitter

Open wangxuepeng opened this issue 7 years ago • 10 comments

Set splitter as below: <SplitPane defaultSize="50%" split="vertical"> <div>a</div> <div>b</div> </SplitPane>

At page load, the splitter will stay at the center of the window. If you change the window size, you can see the splitter is always keep in the center of the window.

Then, if you manual change the splitter, e.g., move a little to left/right, then change the window size, you will see the splitter just stay at the fixed location where it is, not auto adapt to the correct percentage location as above.

Open the image to see detail

Is that a bug? How to keep the splitter in percentage location with window size change?

Thanks.

wangxuepeng avatar Oct 16 '16 11:10 wangxuepeng

Is that a bug or design intend? any plan to resolve this? Thanks.

wangxuepeng avatar Nov 04 '16 14:11 wangxuepeng

If there is a solution to this I also would like to know.

death667b avatar Nov 17 '16 04:11 death667b

This was intended - you start with a percentage value, but as soon as you move the resizer you have repositioned it, and it will then stay in that position.

Maybe this behaviour is unexpected? It could perhaps be a configuration option?

tomkp avatar Nov 17 '16 20:11 tomkp

It's good if this can be a configuration option, especially in scenario like below:

User move the resizer to a 80% width position, then, user adjusted the window to a size less than 80% width of the original window, in such case, the resizer bar will stay in 'hidden' view and can't see or use it.

wangxuepeng avatar Nov 18 '16 02:11 wangxuepeng

I also would like the ability for the user to set a percentage width or height, depending on config. If they then resize the browser the sizing stays the same.

It would also need to not go below or above min/max values - percent or static number.

death667b avatar Nov 19 '16 11:11 death667b

Also that would be pretty good to have a configuration option so that "everything inside" is set to percent, especially the value returned by onChange. So that we can control the react component with percentage only !

olup avatar Jan 25 '17 09:01 olup

+1 if this can be implemented in the newer version. Currently hacking the code to make it percentage-wise. Thanks.@tomkp

yuxincs avatar Feb 08 '18 17:02 yuxincs

+1 for auto adapting to window size. @yxwangcs just curious, how did you hack this?

ct6502 avatar Jun 17 '19 20:06 ct6502

@chris-torrence, I was hacking the source code of react-split-pane more than a year ago, so it may not apply for the code today.

The idea is to calculate a parentSize of SplitPane around this line and try to pass it into Pane class, then in Pane class (these lines) set the width and height to a percent-based string. Something like (not tested on today's code)

if (size !== undefined) {
        if (split === 'vertical') {
          style.width = typeof size === 'string' && size.endsWith('%') ? size : size / parentSize * 100 + '%';
        } else {
          style.height = typeof size === 'string' && size.endsWith('%') ? size : size / parentSize * 100 + '%';
          style.display = 'flex';
        }
        style.flex = 'none';
      }

Hope this helps.

yuxincs avatar Jun 18 '19 18:06 yuxincs

hey @yxwangcs thanks for the code - I'll give it a try!

ct6502 avatar Jun 18 '19 23:06 ct6502