diff --git a/packages/bits-ui/src/lib/bits/accordion/accordion.svelte.ts b/packages/bits-ui/src/lib/bits/accordion/accordion.svelte.ts index 5fe896f6a..863f07ebb 100644 --- a/packages/bits-ui/src/lib/bits/accordion/accordion.svelte.ts +++ b/packages/bits-ui/src/lib/bits/accordion/accordion.svelte.ts @@ -287,11 +287,14 @@ type AccordionContentStateProps = BoxedValues<{ class AccordionContentState { item = undefined as unknown as AccordionItemState; - currentStyle = box>({}); - isMountAnimationPrevented = box(false); + currentStyle = box<{ transitionDuration: string; animationName: string } | undefined>( + undefined + ); + isMountAnimationPrevented = $state(false); width = box(0); height = box(0); presentEl: Box = box(undefined); + present = $derived(this.item.isSelected); #attrs: Record = $derived({ "data-state": getDataOpenClosed(this.item.isSelected), @@ -299,19 +302,23 @@ class AccordionContentState { "data-value": this.item.value, "data-accordion-content": "", style: styleToString({ - "--bits-accordion-content-height": `${this.height.value}px`, - "--bits-accordion-content-width": `${this.width.value}px`, + "--bits-accordion-content-height": this.height.value + ? `${this.height.value}px` + : undefined, + "--bits-accordion-content-width": this.width.value + ? `${this.width.value}px` + : undefined, }), }); constructor(props: AccordionContentStateProps, item: AccordionItemState) { this.item = item; - this.isMountAnimationPrevented.value = this.item.isSelected; + this.isMountAnimationPrevented = this.item.isSelected; this.presentEl = props.presentEl; onMount(() => { requestAnimationFrame(() => { - this.isMountAnimationPrevented.value = false; + this.isMountAnimationPrevented = false; }); }); @@ -336,15 +343,10 @@ class AccordionContentState { this.width.value = rect.width; // unblock any animations/transitions that were originally set if not the initial render - if (!this.isMountAnimationPrevented.value) { - const transitionDuration = this.currentStyle.value.transitionDuration; - const animationName = this.currentStyle.value.animationName; - if (transitionDuration) { - node.style.transitionDuration = transitionDuration; - } - if (animationName) { - node.style.animationName = animationName; - } + if (!this.isMountAnimationPrevented) { + const { animationName, transitionDuration } = this.currentStyle.value; + node.style.transitionDuration = transitionDuration; + node.style.animationName = animationName; } }); } diff --git a/packages/bits-ui/src/lib/bits/accordion/components/accordion-content.svelte b/packages/bits-ui/src/lib/bits/accordion/components/accordion-content.svelte index 5eb123b30..2ecbefeb2 100644 --- a/packages/bits-ui/src/lib/bits/accordion/components/accordion-content.svelte +++ b/packages/bits-ui/src/lib/bits/accordion/components/accordion-content.svelte @@ -3,7 +3,6 @@ import type { AccordionContentProps } from "../types.js"; import Presence from "$lib/bits/utilities/presence.svelte"; import { box } from "$lib/internal/box.svelte.js"; - import { styleToString } from "$lib/internal/style.js"; let { child, @@ -32,19 +31,15 @@ {#if asChild} {@render child?.({ props: { ...mergedProps, hidden: !present.value } })} {:else} - - -