mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
fix(expandable-tile): set tile max height using Resize Observer
This commit is contained in:
parent
4460f5b5f8
commit
44ff46102a
1 changed files with 14 additions and 4 deletions
|
@ -32,11 +32,23 @@
|
||||||
/** Obtain a reference to the top-level element */
|
/** Obtain a reference to the top-level element */
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { afterUpdate } from "svelte";
|
import { afterUpdate, onMount } from "svelte";
|
||||||
import ChevronDown from "../icons/ChevronDown.svelte";
|
import ChevronDown from "../icons/ChevronDown.svelte";
|
||||||
|
|
||||||
let refAbove = null;
|
let refAbove = null;
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
const resizeObserver = new ResizeObserver(([elem]) => {
|
||||||
|
tileMaxHeight = elem.contentRect.height;
|
||||||
|
});
|
||||||
|
|
||||||
|
resizeObserver.observe(refAbove);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
resizeObserver.disconnect();
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
if (tileMaxHeight === 0) {
|
if (tileMaxHeight === 0) {
|
||||||
tileMaxHeight = refAbove.getBoundingClientRect().height;
|
tileMaxHeight = refAbove.getBoundingClientRect().height;
|
||||||
|
@ -62,10 +74,8 @@
|
||||||
class:bx--tile--expandable="{true}"
|
class:bx--tile--expandable="{true}"
|
||||||
class:bx--tile--is-expanded="{expanded}"
|
class:bx--tile--is-expanded="{expanded}"
|
||||||
class:bx--tile--light="{light}"
|
class:bx--tile--light="{light}"
|
||||||
|
style:max-height="{expanded ? "none" : `${tileMaxHeight + tilePadding}px`}"
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
style="{expanded
|
|
||||||
? $$restProps.style
|
|
||||||
: `${$$restProps.style}; max-height: ${tileMaxHeight + tilePadding}px`}"
|
|
||||||
on:click
|
on:click
|
||||||
on:click="{() => {
|
on:click="{() => {
|
||||||
expanded = !expanded;
|
expanded = !expanded;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue