refactor(code-snippet): use afterUpdate

This commit is contained in:
Eric Liu 2019-12-25 07:20:57 -08:00
commit 152cbcd1ab

View file

@ -11,6 +11,7 @@
export let light = false; export let light = false;
export let style = undefined; export let style = undefined;
import { afterUpdate } from 'svelte';
import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16'; import ChevronDown16 from 'carbon-icons-svelte/lib/ChevronDown16';
import { cx } from '../../lib'; import { cx } from '../../lib';
import Button from '../Button'; import Button from '../Button';
@ -22,10 +23,11 @@
let expanded = false; let expanded = false;
let showMoreLess = false; let showMoreLess = false;
$: expandText = expanded ? showLessText : showMoreText; afterUpdate(() => {
$: if (codeRef) {
showMoreLess = type === 'multi' && codeRef.getBoundingClientRect().height > 255; showMoreLess = type === 'multi' && codeRef.getBoundingClientRect().height > 255;
} });
$: expandText = expanded ? showLessText : showMoreText;
</script> </script>
{#if type === 'inline'} {#if type === 'inline'}