From 42e65e400f52e392f430aa692d9305ecf0867098 Mon Sep 17 00:00:00 2001 From: Hunter Johnston Date: Thu, 11 Apr 2024 19:52:49 -0400 Subject: [PATCH] get rid of `removeUndefined` in accordion --- .../bits/accordion/components/accordion.svelte | 2 +- .../src/lib/bits/accordion/state.svelte.ts | 16 ++++++---------- packages/bits-ui/src/lib/bits/accordion/types.ts | 6 +++--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/bits-ui/src/lib/bits/accordion/components/accordion.svelte b/packages/bits-ui/src/lib/bits/accordion/components/accordion.svelte index cc00b57b6..e15bb9b6a 100644 --- a/packages/bits-ui/src/lib/bits/accordion/components/accordion.svelte +++ b/packages/bits-ui/src/lib/bits/accordion/components/accordion.svelte @@ -9,7 +9,7 @@ children, child, type, - value, + value = $bindable(), el, ...restProps }: AccordionRootProps = $props(); diff --git a/packages/bits-ui/src/lib/bits/accordion/state.svelte.ts b/packages/bits-ui/src/lib/bits/accordion/state.svelte.ts index 9e0d7feed..b4ace0d54 100644 --- a/packages/bits-ui/src/lib/bits/accordion/state.svelte.ts +++ b/packages/bits-ui/src/lib/bits/accordion/state.svelte.ts @@ -6,7 +6,6 @@ import { dataDisabledAttrs, kbd, openClosedAttrs, - removeUndefined, verifyContextDeps, } from "$lib/internal/index.js"; @@ -33,7 +32,7 @@ class AccordionBaseState { constructor(props: AccordionBaseStateProps = {}) { const mergedProps = { ...defaultAccordionRootBaseProps, - ...removeUndefined(props), + ...props, } satisfies AccordionBaseStateProps; this.el = mergedProps.el; this.disabled = mergedProps.disabled; @@ -64,7 +63,7 @@ export class AccordionSingleState extends AccordionBaseState { constructor(props: AccordionSingleStateProps = {}) { const mergedProps = { ...defaultAccordionRootSingleProps, - ...removeUndefined(props), + ...props, } satisfies AccordionSingleStateProps; super(mergedProps); this.value = mergedProps.value; @@ -98,7 +97,7 @@ export class AccordionMultiState extends AccordionBaseState { constructor(props: AccordionMultiStateProps = {}) { const mergedProps = { ...defaultAccordionRootMultiProps, - ...removeUndefined(props), + ...props, } satisfies AccordionMultiStateProps; super(mergedProps); @@ -329,8 +328,7 @@ export function getAccordionRootState(): AccordionState { export function setAccordionItemState(props: Omit) { verifyContextDeps(ACCORDION_ROOT); - const rootState = getAccordionRootState(); - const itemState = new AccordionItemState({ ...props, rootState }); + const itemState = new AccordionItemState({ ...props, rootState: getAccordionRootState() }); setContext(ACCORDION_ITEM, itemState); return itemState; } @@ -341,12 +339,10 @@ export function getAccordionItemState(): AccordionItemState { export function getAccordionTriggerState(props: AccordionTriggerStateProps): AccordionTriggerState { verifyContextDeps(ACCORDION_ITEM); - const itemState = getAccordionItemState(); - return itemState.createTrigger(props); + return getAccordionItemState().createTrigger(props); } export function getAccordionContentState(): AccordionContentState { verifyContextDeps(ACCORDION_ITEM); - const itemState = getAccordionItemState(); - return itemState.createContent(); + return getAccordionItemState().createContent(); } diff --git a/packages/bits-ui/src/lib/bits/accordion/types.ts b/packages/bits-ui/src/lib/bits/accordion/types.ts index 998a3cd54..60e40fa54 100644 --- a/packages/bits-ui/src/lib/bits/accordion/types.ts +++ b/packages/bits-ui/src/lib/bits/accordion/types.ts @@ -23,9 +23,9 @@ interface MultipleAccordionProps extends BaseAccordionProps { value?: string[]; } -export type AccordionRootPropsWithoutHTML = WithAsChild< - SingleAccordionProps | MultipleAccordionProps ->; +export type AccordionRootPropsWithoutHTML = + | WithAsChild + | WithAsChild; export type AccordionRootProps = AccordionRootPropsWithoutHTML & PrimitiveDivAttributes;