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

Update height in dynamic content #75

Open
rhernandog opened this issue Oct 23, 2019 · 4 comments
Open

Update height in dynamic content #75

rhernandog opened this issue Oct 23, 2019 · 4 comments

Comments

@rhernandog
Copy link

rhernandog commented Oct 23, 2019

Hello,

Thanks for this package is really neat!!!

I'd like to know if there is a way to update the height of the scrollbar when the content's height changes. Basically I'm trying to add this to a vertical menu on a sidebar. The issue is that some of the menu elements have submenus, so the content's height changes whenever those are opened and closed.

Here is a live reduced sample of what I'm trying to build:

https://codesandbox.io/s/adoring-hodgkin-4ikzz

Also there is another issue when the elements are expanded and then collapsed, the scrollbar is still visible even though the content's height fits the parent element. To reproduce, expand all elements and then collapse them all.

@rommguy
Copy link
Owner

rommguy commented Oct 24, 2019

Thanks, I'm glad you like it.
I need to check. I think you have to render the CustomScroll component somehow after the menu changes size, for the changes to affect the scroll appearance. Otherwise, there is no way the code that calculates the sizes will run - nothing to trigger it.

@spennythug
Copy link

spennythug commented Nov 14, 2019

I was running into a similar situation and was able to get around it by calling forceUpdate on a ref. This might not be best practice but it's a decent solution without making any changes to the package.

Here is a pseudo code example.

constructor() {  
  this.scrollRef = React.createRef();
}

render() {
  return <CustomScroll ref={this.scrollRef}></CustomScroll>
}

theHeightHasChanged(){
  this.scrollRef.current.forceUpdate();
}

@rommguy
Copy link
Owner

rommguy commented Nov 17, 2019

I think that's the solution I would go with, or render the customScroll's parent component if you want to avoid the ref usage.

@rhernandog
Copy link
Author

@rommguy & @spennythug I had to work on some other aspects of the project so I abandoned this for a while. The solution actually works in some fashion but there are a few glitches regarding the size of the scroll handler not being updated as the height of the content is updated and the position somehow jumping around on the next scroll event, after the content size is updated.

Since this is not some code I'm very familiar with it I crafted my own solution using GSAP (https://greensock.com/), since I'm already using it in the project. Is still a work in progress and because of the project's specs it only works in desktop and laptops (since devices have already a good looking UI when it comes to scrolling there is no need to change it) but it does what we need.

Repo
https://github.com/rhernandog/react-custom-scrollbar

Live Preview in Codesandbox
https://30jdm.csb.app/

Live Sample in Codesandbox
https://codesandbox.io/s/github/rhernandog/react-custom-scrollbar

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

3 participants