Skip to content

Commit

Permalink
Merge pull request #1012 from suraj776/bug/#1009
Browse files Browse the repository at this point in the history
[Bug]: TypeError: Cannot read properties of undefined (reading 'map') in AutoHeight
  • Loading branch information
davidjerleke authored Sep 24, 2024
2 parents 4ebb8c3 + 0a6772c commit 2af08af
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}

Expand Down

0 comments on commit 2af08af

Please sign in to comment.