$api?. => $api. when possible
Now that this stuff has all been cleaned up with useXContext functions
This commit is contained in:
@@ -103,5 +103,5 @@
|
||||
</script>
|
||||
|
||||
<div {...$$restProps}>
|
||||
<slot open={disclosureState === DisclosureStates.Open} close={$api?.close} />
|
||||
<slot open={disclosureState === DisclosureStates.Open} close={$api.close} />
|
||||
</div>
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
const panelContext = usePanelContext();
|
||||
const id = `headlessui-disclosure-button-${useId()}`;
|
||||
|
||||
$: buttonStore = $api?.buttonStore;
|
||||
$: panelStore = $api?.panelStore;
|
||||
$: buttonStore = $api.buttonStore;
|
||||
$: panelStore = $api.panelStore;
|
||||
|
||||
$: isWithinPanel =
|
||||
panelContext === null ? false : panelContext === $api?.panelId;
|
||||
panelContext === null ? false : panelContext === $api.panelId;
|
||||
|
||||
function handleClick() {
|
||||
if (disabled) return;
|
||||
@@ -68,7 +68,7 @@
|
||||
"aria-expanded": disabled
|
||||
? undefined
|
||||
: $api.disclosureState === DisclosureStates.Open,
|
||||
"aria-controls": $panelStore ? $api?.panelId : undefined,
|
||||
"aria-controls": $panelStore ? $api.panelId : undefined,
|
||||
disabled: disabled ? true : undefined,
|
||||
};
|
||||
</script>
|
||||
@@ -80,8 +80,8 @@
|
||||
on:keydown={handleKeyDown}
|
||||
>
|
||||
<slot
|
||||
open={$api?.disclosureState === DisclosureStates.Open}
|
||||
close={$api?.close}
|
||||
open={$api.disclosureState === DisclosureStates.Open}
|
||||
close={$api.close}
|
||||
/>
|
||||
</button>
|
||||
{:else}
|
||||
@@ -93,8 +93,8 @@
|
||||
on:keyup={handleKeyUp}
|
||||
>
|
||||
<slot
|
||||
open={$api?.disclosureState === DisclosureStates.Open}
|
||||
close={$api?.close}
|
||||
open={$api.disclosureState === DisclosureStates.Open}
|
||||
close={$api.close}
|
||||
/>
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
@@ -11,17 +11,17 @@
|
||||
import { useDisclosureContext, DisclosureStates } from "./Disclosure.svelte";
|
||||
import { State, useOpenClosed } from "$lib/internal/open-closed";
|
||||
const api = useDisclosureContext("DisclosureButton");
|
||||
$: id = $api?.panelId;
|
||||
$: id = $api.panelId;
|
||||
let openClosedState = useOpenClosed();
|
||||
|
||||
setContext(DISCLOSURE_PANEL_CONTEXT_NAME, id);
|
||||
|
||||
$: panelStore = $api?.panelStore;
|
||||
$: panelStore = $api.panelStore;
|
||||
|
||||
$: visible =
|
||||
$openClosedState !== null
|
||||
? $openClosedState === State.Open
|
||||
: $api?.disclosureState === DisclosureStates.Open;
|
||||
: $api.disclosureState === DisclosureStates.Open;
|
||||
|
||||
$: propsWeControl = { id };
|
||||
</script>
|
||||
@@ -29,8 +29,8 @@
|
||||
{#if visible}
|
||||
<div {...{ ...$$restProps, ...propsWeControl }} bind:this={$panelStore}>
|
||||
<slot
|
||||
open={$api?.disclosureState === DisclosureStates.Open}
|
||||
close={$api?.close}
|
||||
open={$api.disclosureState === DisclosureStates.Open}
|
||||
close={$api.close}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user