nuka-carousel icon indicating copy to clipboard operation
nuka-carousel copied to clipboard

Initial height is broken

Open balazsorban44 opened this issue 8 years ago • 28 comments

Describe Your Environment

  • What version of nuka-carousel are you using? latest
  • What version of React are you using? latest
  • What browser are you using? chrome
  • What machine are you on? linux

Describe the Problem

Expected behavior: [What you expect to happen] That the initial height is the first (or the tallest) image's height Actual behavior: [What actually happens] No matter what I set, the initial height is 100px Example: Edit o58601znvq

Additional Information

I wrote about this at the issue #413 but I move it into a new issue for clearance.

When the carousel first loads, it is only 100px high, no matter what I set where. Changing to the next slide, or resizing the window, everything snaps into place, and the height becomes the image's height as it is supposed to be.

balazsorban44 avatar Sep 22 '18 07:09 balazsorban44

@balazsorban44 : we absorb the behavior only in Sandbox and not when you install and run the package in a browser. Could you let us know if you face the issue outside CodeSandbox?

ashika01 avatar Sep 24 '18 22:09 ashika01

might be related to https://github.com/FormidableLabs/nuka-carousel/issues/349

stunaz avatar Sep 25 '18 00:09 stunaz

@ashika01 I do have the same problem in my browser, yes.

@stunaz It looks like that his problem is with the width. Mine is the height.

balazsorban44 avatar Sep 25 '18 06:09 balazsorban44

Same issue, the initial height is always miscalculated for some reason. Once i slide to the next slide, it readjusts correctly

dennis3124 avatar Sep 26 '18 22:09 dennis3124

Might be useful for some - here's a veeeery hacky workaround I've been using to get the carousel to the correct height without having to interact with it first

componentDidMount(){
    setTimeout(() => {
        try {
            this._carousel.setDimensions(null)
        }
        catch(err){
                // sometimes it crashes in chrome, pristine error handling here
        }
    }, 200);
}

amomentunfolding avatar Sep 27 '18 11:09 amomentunfolding

@synekdok Since more of us has the same problem, I don't feel that we should make hacks to solve it, rather implement the solution directly in this package!

balazsorban44 avatar Sep 27 '18 20:09 balazsorban44

Also, when using in modal position fixed, height/width 100%. and using image ratio % trick. slides are rendering at 20px height on first load until resize is triggered. Also it only resizes properly when it's the width that changes in the resize, not height.

need to address resizing height properly when height changes and width does not.

example code: https://codesandbox.io/s/j4n5046k7w

NubSoup avatar Sep 28 '18 17:09 NubSoup

In my case, the initial height is 0,

Edit pkx5p4jj9x

edwinharly avatar Oct 02 '18 02:10 edwinharly

Explicitly setting the image width and height attributes fixed this for me. However this is totally an issue in a production site with v4.3.7

https://codesandbox.io/s/9zy4nz3684

ianregister avatar Oct 02 '18 22:10 ianregister

Explicitly setting the image width and height attributes fixed this for me. However this is totally an issue in a production site with v4.3.7

https://codesandbox.io/s/9zy4nz3684

Are you using percentages or px values? I believe this is still an issue for percentages for those that want to use a more responsive approach.

NubSoup avatar Oct 03 '18 17:10 NubSoup

Any news?

CharlyJazz avatar Oct 04 '18 22:10 CharlyJazz

Explicitly setting the image width and height attributes fixed this for me. However this is totally an issue in a production site with v4.3.7

https://codesandbox.io/s/9zy4nz3684

it works only when the img counts is static, doesn't work when it's dynamic (using map)

edwinharly avatar Oct 08 '18 07:10 edwinharly

Taking a look at this trace:

findMaxHeightSlide      @ index.js:794
getSlideHeight          @ index.js:815
calcSlideHeightAndWidth @ index.js:830
setDimensions           @ index.js:874
componentDidMount       @ index.js:180

We see that we're getting to this function:

  findMaxHeightSlide(slides) {
    let maxHeight = 0;
    for (let i = 0; i < slides.length; i++) {
      if (slides[i].offsetHeight > maxHeight) {
        maxHeight = slides[i].offsetHeight;
      }
    }
    return maxHeight;
  }

But slides is an empty NodeList, which is causing maxHeight to be 0.

ryanwalters avatar Oct 09 '18 21:10 ryanwalters

@ryanwalters are you referring to this file: https://github.com/FormidableLabs/nuka-carousel/blob/master/src/index.js? I see totally uncorrelated line numbers. Eg.: componentDidMount is on line 118, not 180. Or maybe I misunderstood. Could you lighten me up? 💡

I can see that initialSlideHeight was tempered with not so long ago, and its implementation has been reverted in this commit: https://github.com/FormidableLabs/nuka-carousel/commit/9b7063a545e2d2b30dce76b7eda7742622a5d31f. Now, I did not go deep into the code, but the number 100 shows up as a fallback height, which is exactly what I am experiencing! Can there be a relation between this commit and our issue @sarmeyer? 🤔

balazsorban44 avatar Oct 09 '18 22:10 balazsorban44

Those line numbers are from the production build version in the node_modules folder. Should have specified that, my bad.

ryanwalters avatar Oct 09 '18 22:10 ryanwalters

I seem to be having a similar issue as this but my initial height is huge (1286px). Cant seem to change it either with initialSlideHeight.

edit: I had to set the slides width to anything other than a percentage (100vw worked for me) and voilà!

cwahlfeldt avatar Oct 10 '18 21:10 cwahlfeldt

Also experiencing these issues:

  1. initialSlideHeight is useless (has no effect)
  2. most of the time the slider initially sets height to 18px (this varies apparently) and covers up slide before slide image loads, sometimes (less often) the initial height is very big and is all whitespace.

jflayhart avatar Oct 18 '18 14:10 jflayhart

Same issue here

rdgomt avatar Oct 19 '18 13:10 rdgomt

Same issue here. When images get loaded from an API, the height is always auto/100px. InitialSlideHeight and heightMode are both not working when they're set.

We had to trigger a resize event on load for our ImageArray to get it to work, which is not really ideal but at least it works for now. Keen to hear when this gets fixed too!

alaskaa avatar Oct 25 '18 06:10 alaskaa

I was able to resolve for a full screen responsive image carousel by measuring the image size based on the screen size and then merging the height into the settings array for initialSlideHeight. Weirdly as a px value rather than integer. This meant I did not need to do any resize events. I'll put a codepen example up when I get a chance.

ianregister avatar Oct 25 '18 06:10 ianregister