Initial height is broken
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:
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 : 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?
might be related to https://github.com/FormidableLabs/nuka-carousel/issues/349
@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.
Same issue, the initial height is always miscalculated for some reason. Once i slide to the next slide, it readjusts correctly
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);
}
@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!
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
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
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.
Any news?
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)
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 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? 🤔
Those line numbers are from the production build version in the node_modules folder. Should have specified that, my bad.
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à!
Also experiencing these issues:
- initialSlideHeight is useless (has no effect)
- 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.
Same issue here
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!
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.