From 884f89d89126e6c04f5b3b13c19556df368e47f2 Mon Sep 17 00:00:00 2001 From: Crash-- Date: Mon, 28 Nov 2022 13:45:25 +0100 Subject: [PATCH] fix: Fix bottomSheet height if the content is pretty small If the innerContent is smaller than the mediumHeight, we don't want the BottomSheet to take all the available space. We want to take only the needed place. --- react/BottomSheet/helpers.js | 3 +-- react/BottomSheet/helpers.spec.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/react/BottomSheet/helpers.js b/react/BottomSheet/helpers.js index 5ac14552a8..b26905c3c7 100644 --- a/react/BottomSheet/helpers.js +++ b/react/BottomSheet/helpers.js @@ -26,7 +26,6 @@ export const computeMediumHeight = ({ }) => { const mediumHeightOrWithRatio = mediumHeight || Math.round(maxHeight * mediumHeightRatio) - if (backdrop) { if (mediumHeightOrWithRatio < innerContentHeight) { return mediumHeightOrWithRatio < maxHeight @@ -35,7 +34,7 @@ export const computeMediumHeight = ({ } return innerContentHeight > maxHeight ? maxHeight : innerContentHeight } - + if (innerContentHeight < mediumHeightOrWithRatio) return innerContentHeight return mediumHeightOrWithRatio > maxHeight ? maxHeight : mediumHeightOrWithRatio diff --git a/react/BottomSheet/helpers.spec.js b/react/BottomSheet/helpers.spec.js index bc05cb341d..76fa4df2b2 100644 --- a/react/BottomSheet/helpers.spec.js +++ b/react/BottomSheet/helpers.spec.js @@ -57,6 +57,17 @@ describe('computeMediumHeight', () => { expect(res).toBe(800) }) + + it('should return the innerContentHeight if innerContentHeight < mediumHeight', () => { + const res = computeMediumHeight({ + backdrop: false, + maxHeight: 800, + mediumHeight: 400, + innerContentHeight: 200 + }) + + expect(res).toBe(200) + }) }) describe('with backdrop', () => {