Height is always equal to first slide's height
Hi, I found an issue where the slider height is always equal to the first slide's height. When other slides are taller, they are getting cut off.
Here in the setDimensions function the slide height is set equal to the first slide's height.
https://github.com/FormidableLabs/nuka-carousel/blob/master/src/carousel.js#L788
I think to actually get the largest slide's height we need to iterate through them like so:
setDimensions: function setDimensions(props) {
props = props || this.props;
var self = this,
slideWidth,
slidesToScroll,
firstSlide,
frame,
frameWidth,
frameHeight,
slideHeight;
slidesToScroll = props.slidesToScroll;
frame = this.refs.frame;
firstSlide = frame.childNodes[0].childNodes[0];
if (firstSlide) {
// iterate through the slides to find the biggest height
var biggestHeight = 0;
(frame.childNodes[0].childNodes).forEach(function(node) {
if (node.offsetHeight > biggestHeight) {
biggestHeight = node.offsetHeight;
}
});
firstSlide.style.height = 'auto';
slideHeight = this.props.vertical ? firstSlide.offsetHeight * props.slidesToShow : biggestHeight;
} else {
slideHeight = 100;
}
if (typeof props.slideWidth !== 'number') {
slideWidth = parseInt(props.slideWidth);
} else {
if (props.vertical) {
slideWidth = slideHeight / props.slidesToShow * props.slideWidth;
} else {
slideWidth = frame.offsetWidth / props.slidesToShow * props.slideWidth;
}
}
if (!props.vertical) {
slideWidth -= props.cellSpacing * ((100 - 100 / props.slidesToShow) / 100);
}
frameHeight = slideHeight + props.cellSpacing * (props.slidesToShow - 1);
frameWidth = props.vertical ? frameHeight : frame.offsetWidth;
if (props.slidesToScroll === 'auto') {
slidesToScroll = Math.floor(frameWidth / (slideWidth + props.cellSpacing));
}
this.setState({
slideHeight: slideHeight,
frameWidth: frameWidth,
slideWidth: slideWidth,
slidesToScroll: slidesToScroll,
left: props.vertical ? 0 : this.getTargetLeft(),
top: props.vertical ? this.getTargetLeft() : 0
}, function () {
self.setLeft();
});
},
Is this still an issue on [email protected]+ now that we've landed https://github.com/FormidableLabs/nuka-carousel/pull/291?
Hi, I still have the problem on [email protected] The carousel is initialized with the first slide height, and the next image slides are cut off...
I also have this, even after upgrading to 4.1.0.
@Pruxis @MatBdry @brendangkchan
Does this bug happen even when using the heightMode="MAX" prop?
@ryan-roemer Do you suppose it would make sense to make this the default?
@mhink I have another problem when I set heightMode="max", but I don't know if it depends on this property. The first slide is cut off when the carousel is initialized:

Then, when I change the slide, the height is ok:

@MatBdry Hello, I'm trying to repro the bug you're finding when you set heightMode="max". When I do it on my local copy using [email protected] it seems to calculate the "max" height properly based on the tallest slide (whether it's the last, first, or somewhere in the center). And the carousel renders correctly on the first slide and each one after.
Can you post some code to help us repro the bug you're getting? Or use something like https://codesandbox.io/ to code up a sample that shows off the bug?