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; - });