react-custom-scrollbars icon indicating copy to clipboard operation
react-custom-scrollbars copied to clipboard

AutoHeight with unknown maxHeight?

Open TheOpti opened this issue 8 years ago • 12 comments

Right now autoHeightMin, autoHeightMax take parameter of type number, which means number of pixels. How can I pass something like 'calc(100vh - 120px)' as my max height in scroll container?

Is it possible right now?

TheOpti avatar Feb 15 '17 17:02 TheOpti

Not 100% sure, but it might be as folloing:

autoHeightMin={`calc(100vh - 120px)`}

Dmitry-N-Medvedev avatar Feb 16 '17 23:02 Dmitry-N-Medvedev

I can confirm @Dmitry-N-Medvedev's solution works. Would be good to add to docs.

KyleAMathews avatar Mar 07 '17 18:03 KyleAMathews

Yeah, it works, but what if I would like to have the height to be 100% of the container?

  • Setting it ` autoHeightMin={100%} , makes it about 200px high,
  • setting it autoHeightMin={calc(100vh)} disables scroll events, because height than, is indeed 100vh, not fitting the container.

sebhewelt avatar May 08 '17 22:05 sebhewelt

same problem here, i'd like it to be 100% height of it's container but nothing that I use works

stevenmusumeche avatar Jul 30 '17 19:07 stevenmusumeche

well i was hopping there was a way to set a real auto height that fit to the container or the first positioned relative parent. No luck so far.

sag1v avatar Oct 26 '17 12:10 sag1v

I found

<Scrollbars style={{ height: '100%' }}></Scrollbars>

does not work.

But

<Scrollbars autoHeight autoHeightMin="100%" autoHeightMax="100%"></Scrollbars>

works for me!

hongbo-miao avatar Nov 02 '17 04:11 hongbo-miao

Also having this issue... unknown maxHeight 🤷‍♂️

drewlustro avatar Nov 03 '17 18:11 drewlustro

Had the opposite effect that @Hongbo-Miao had. style={{ height: '100%' }}

Worked great for me, where autoHeight, didn't work. Not quite sure why.

team-moonrise avatar Nov 10 '17 15:11 team-moonrise

Hmm... style={{ height: '100%' }} worked for me as well... I'm not positive, but I think it really depends on how your parent container elements are defined. If your parent element defines it's height according to it's content, then you'll probably need to use autoHeight somehow. On the other hand, if your parent element defines it's height according to it's own space available, then style={{ height: '100%' }} will probably be the way to go.

In my case, I had a flexbox column container with setting auto. This was not working, apparently because of the auto flex-basis, which sets the initial height of the flex container to the size of its content -- the result was a 0 height scrollbar and content. Changing this to flex 1 1 0 (same as auto, but with a non-content based flex-basis) fixed the problem.

It's likely this just needs some documentation and some samples to know how to use it properly in various situations.

rocketraman avatar Apr 02 '18 16:04 rocketraman

Good point @rocketraman! style={{ height: '100%' }} works well to me when I set height: '100%' for the parent container.

ikorgik avatar May 09 '18 14:05 ikorgik

i use <Scrollbars autoHeight autoHeightMin={100} autoHeightMax="calc(80vh - 36px - 35px - 75px)"> content scroll </Scrollbars> it work for me

kiennguyen278 avatar Mar 29 '20 10:03 kiennguyen278

Hi everyone, I had the same issue.

As my parent has display: flex; height: 100% I use <Scrollbars style={{ flex: 1 }}>{children}</Scrollbars>

It works like a charm ;)

vladi-strilets avatar Sep 28 '20 00:09 vladi-strilets