From 662c7b7fdea7d593a94af66e9d2a6f745d931336 Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 9 May 2020 07:23:06 -0700 Subject: [PATCH] fix(tile): set max height using aboveRef only if value is 0 Fixes #180 --- src/components/Tile/ExpandableTile.svelte | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/components/Tile/ExpandableTile.svelte b/src/components/Tile/ExpandableTile.svelte index 27cc7592..1ffb9d4f 100644 --- a/src/components/Tile/ExpandableTile.svelte +++ b/src/components/Tile/ExpandableTile.svelte @@ -11,7 +11,7 @@ export let tileMaxHeight = 0; export let tilePadding = 0; - import { onMount, afterUpdate } from 'svelte'; + import { afterUpdate } from 'svelte'; import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16'; import { cx, css } from '../../lib'; @@ -19,20 +19,17 @@ let contentRef = undefined; let aboveRef = undefined; - onMount(() => { - const style = window.getComputedStyle(tileRef); + afterUpdate(() => { + if (tileMaxHeight === 0) { + tileMaxHeight = aboveRef.getBoundingClientRect().height; + } - tileMaxHeight = aboveRef.getBoundingClientRect().height; + const style = window.getComputedStyle(tileRef); + tilePadding = parseInt(style.getPropertyValue('padding-top'), 10) + parseInt(style.getPropertyValue('padding-bottom'), 10); }); - - afterUpdate(() => { - tileMaxHeight = expanded - ? contentRef.getBoundingClientRect().height - : aboveRef.getBoundingClientRect().height; - });