react-slick icon indicating copy to clipboard operation
react-slick copied to clipboard

Recalculate height when content of slide has been changed

Open martinpesout opened this issue 10 years ago • 6 comments

Is there any way how to recalculate height of slide when content has been changed? I'm using adaptiveHeight feature and when I change something in active slide, content will overflow.

I'll give one example:

      <Slider ref="slider" {...settings}>
        <div> ... content of first slide ... </div>
        <div> ... content of second slide ... </div>
        <div> ... content of third slide ... </div>
      </Slider>

I've found that the only way is to call this.refs.slider.forceUpdate() to recalculate height. But I have to do it every time I change content. Is there any chance to implement some workaround for auto-correction of height?

martinpesout avatar Oct 13 '16 11:10 martinpesout

@martinpesout I'm having the same issue in gatsbyjs when in when running the dev env. But not when serving the compiled production build. So it most probably has something to do with the fact CSS is not entirely loaded yet when react-slick is calculating it's components. Most probably because the CSS is injected using style tags which is often done in hot reloading environments (and causes the visible FOUC as well).

I agree it would be great to see this solved within react-slick though, since this doesn't look too nice:

componentDidMount () {
  if (process.env.NODE_ENV === 'development') {
    setTimeout(() => {
      this.slider.forceUpdate()
    }, 0)
  }
}

yn5 avatar Apr 06 '17 17:04 yn5

Any updates for this issue?

wellyal avatar Apr 24 '17 20:04 wellyal

I came up with a solution for this issue. Once I had my Slick component I could get its reference with ref react API like this:

<Slider
        ref={ref => { this.slider = ref }}
        {...slickSettings}
        ...

Then when you wish you could simple call the forceUpdate method form slick`s ref like this:

this.slider.forceUpdate() // Updates height from your slider

wellyal avatar Jun 01 '17 15:06 wellyal

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 24 '18 03:03 stale[bot]

I also have this issue. I have some nested collapses in each slide, which would change height of the slides when opened. But somehow the Slider doesn't resize immediately until I click somewhere.

yuwei-liang avatar Aug 16 '18 01:08 yuwei-liang

I also have this issue. I have some nested collapses in each slide, which would change height of the slides when opened. But somehow the Slider doesn't resize immediately until I click somewhere.

Hello, I have the same problem, how did you solve it?

cristianlazog avatar Jan 25 '22 19:01 cristianlazog