From 0a6772cbf87671f258494f3ab131e1ef5bc9174a Mon Sep 17 00:00:00 2001 From: Suraj Kumar Date: Mon, 23 Sep 2024 13:59:16 +0530 Subject: [PATCH] Bugfix for #1009. --- .../src/components/AutoHeight.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/embla-carousel-auto-height/src/components/AutoHeight.ts b/packages/embla-carousel-auto-height/src/components/AutoHeight.ts index 4b7408c7c..49ca5050f 100644 --- a/packages/embla-carousel-auto-height/src/components/AutoHeight.ts +++ b/packages/embla-carousel-auto-height/src/components/AutoHeight.ts @@ -43,16 +43,21 @@ function AutoHeight(userOptions: AutoHeightOptionsType = {}): AutoHeightType { if (!container.getAttribute('style')) container.removeAttribute('style') } - function highestInView(): number { + function highestInView(): number | null { const { slideRegistry } = emblaApi.internalEngine() const selectedIndexes = slideRegistry[emblaApi.selectedScrollSnap()] + if (!selectedIndexes) return null + return selectedIndexes .map((index) => slideHeights[index]) .reduce((a, b) => Math.max(a, b), 0) } function setContainerHeight(): void { + const height = highestInView() + if (height === null) return + emblaApi.containerNode().style.height = `${highestInView()}px` }