diff --git a/src/lib/components/dialog/Dialog.svelte b/src/lib/components/dialog/Dialog.svelte
index 1a4f6e8..a595712 100644
--- a/src/lib/components/dialog/Dialog.svelte
+++ b/src/lib/components/dialog/Dialog.svelte
@@ -142,7 +142,7 @@
if (containers.size !== 1) return;
if (contains(containers, target)) return;
- $api?.close();
+ $api.close();
await tick();
target?.focus();
}
@@ -154,7 +154,7 @@
if (containers.size > 1) return; // 1 is myself, otherwise other elements in the Stack
event.preventDefault();
event.stopPropagation();
- $api?.close();
+ $api.close();
}
let mounted = false;
@@ -202,7 +202,7 @@
entry.boundingClientRect.width === 0 &&
entry.boundingClientRect.height === 0
) {
- $api?.close();
+ $api.close();
}
}
});
diff --git a/src/lib/components/dialog/DialogOverlay.svelte b/src/lib/components/dialog/DialogOverlay.svelte
index 6ef9100..74de6b3 100644
--- a/src/lib/components/dialog/DialogOverlay.svelte
+++ b/src/lib/components/dialog/DialogOverlay.svelte
@@ -7,7 +7,7 @@
if (event.target !== event.currentTarget) return;
event.preventDefault();
event.stopPropagation();
- $api?.close();
+ $api.close();
}
$: propsWeControl = {
id,
@@ -16,5 +16,5 @@
-
+
diff --git a/src/lib/components/disclosure/Disclosure.svelte b/src/lib/components/disclosure/Disclosure.svelte
index 135c48f..fa2524d 100644
--- a/src/lib/components/disclosure/Disclosure.svelte
+++ b/src/lib/components/disclosure/Disclosure.svelte
@@ -103,5 +103,5 @@
-
+
diff --git a/src/lib/components/disclosure/DisclosureButton.svelte b/src/lib/components/disclosure/DisclosureButton.svelte
index f56c10b..04e62c1 100644
--- a/src/lib/components/disclosure/DisclosureButton.svelte
+++ b/src/lib/components/disclosure/DisclosureButton.svelte
@@ -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,
};
@@ -80,8 +80,8 @@
on:keydown={handleKeyDown}
>
{:else}
@@ -93,8 +93,8 @@
on:keyup={handleKeyUp}
>
{/if}
diff --git a/src/lib/components/disclosure/DisclosurePanel.svelte b/src/lib/components/disclosure/DisclosurePanel.svelte
index adec6b5..9a01839 100644
--- a/src/lib/components/disclosure/DisclosurePanel.svelte
+++ b/src/lib/components/disclosure/DisclosurePanel.svelte
@@ -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 };
@@ -29,8 +29,8 @@
{#if visible}
{/if}
diff --git a/src/lib/components/listbox/ListboxButton.svelte b/src/lib/components/listbox/ListboxButton.svelte
index baa7aeb..23c133d 100644
--- a/src/lib/components/listbox/ListboxButton.svelte
+++ b/src/lib/components/listbox/ListboxButton.svelte
@@ -65,9 +65,9 @@
"aria-controls": $optionsRef?.id,
"aria-expanded": $api.disabled
? undefined
- : $api?.listboxState === ListboxStates.Open,
+ : $api.listboxState === ListboxStates.Open,
"aria-labelledby": $labelRef ? [$labelRef?.id, id].join(" ") : undefined,
- disabled: $api?.disabled === true ? true : undefined,
+ disabled: $api.disabled === true ? true : undefined,
};
diff --git a/src/lib/components/listbox/ListboxOption.svelte b/src/lib/components/listbox/ListboxOption.svelte
index 921278b..0cae55e 100644
--- a/src/lib/components/listbox/ListboxOption.svelte
+++ b/src/lib/components/listbox/ListboxOption.svelte
@@ -11,11 +11,11 @@
let buttonRef = $api.buttonRef;
$: active =
- $api?.activeOptionIndex !== null
- ? $api?.options[$api.activeOptionIndex].id === id
+ $api.activeOptionIndex !== null
+ ? $api.options[$api.activeOptionIndex].id === id
: false;
- $: selected = $api?.value === value;
+ $: selected = $api.value === value;
$: dataRef = {
disabled,
value,
@@ -33,7 +33,7 @@
onMount(() => $api.registerOption(id, dataRef));
onDestroy(() => $api.unregisterOption(id));
- let oldState = $api?.listboxState;
+ let oldState = $api.listboxState;
let oldSelected = selected;
let oldActive = active;
async function updateFocus(
@@ -45,7 +45,7 @@
await tick();
if (newState !== oldState || newSelected !== oldSelected) {
if (newState === ListboxStates.Open && newSelected) {
- $api?.goToOption(Focus.Specific, id);
+ $api.goToOption(Focus.Specific, id);
}
}
if (newState !== oldState || newActive !== oldActive) {
@@ -57,7 +57,7 @@
oldSelected = newSelected;
oldActive = newActive;
}
- $: updateFocus($api?.listboxState, selected, active);
+ $: updateFocus($api.listboxState, selected, active);
async function handleClick(event: MouseEvent) {
if (disabled) return event.preventDefault();
diff --git a/src/lib/components/listbox/ListboxOptions.svelte b/src/lib/components/listbox/ListboxOptions.svelte
index 36c33ef..e330413 100644
--- a/src/lib/components/listbox/ListboxOptions.svelte
+++ b/src/lib/components/listbox/ListboxOptions.svelte
@@ -91,11 +91,11 @@
$: propsWeControl = {
"aria-activedescendant":
- $api?.activeOptionIndex === null
+ $api.activeOptionIndex === null
? undefined
- : $api?.options[$api.activeOptionIndex]?.id,
+ : $api.options[$api.activeOptionIndex]?.id,
"aria-labelledby": $labelRef?.id ?? $buttonRef?.id,
- "aria-orientation": $api?.orientation,
+ "aria-orientation": $api.orientation,
id,
role: "listbox",
tabIndex: 0,
@@ -115,6 +115,6 @@
{...$$restProps}
{...propsWeControl}
>
-
+
{/if}
diff --git a/src/lib/components/menu/MenuButton.svelte b/src/lib/components/menu/MenuButton.svelte
index 5ba2e3a..85f53ed 100644
--- a/src/lib/components/menu/MenuButton.svelte
+++ b/src/lib/components/menu/MenuButton.svelte
@@ -10,8 +10,8 @@
const api = useMenuContext("MenuButton");
const id = `headlessui-menu-button-${useId()}`;
- $: buttonStore = $api?.buttonStore;
- $: itemsStore = $api?.itemsStore;
+ $: buttonStore = $api.buttonStore;
+ $: itemsStore = $api.itemsStore;
async function handleKeyDown(event: KeyboardEvent) {
switch (event.key) {
// Ref: https://www.w3.org/TR/wai-aria-practices-1.2/#keyboard-interaction-13
@@ -80,5 +80,5 @@
on:keydown={handleKeyDown}
on:keyup={handleKeyUp}
>
-
+
diff --git a/src/lib/components/menu/MenuItem.svelte b/src/lib/components/menu/MenuItem.svelte
index 8e10255..61cd8ca 100644
--- a/src/lib/components/menu/MenuItem.svelte
+++ b/src/lib/components/menu/MenuItem.svelte
@@ -10,11 +10,11 @@
const id = `headlessui-menu-item-${useId()}`;
$: active =
- $api?.activeItemIndex !== null
- ? $api?.items[$api?.activeItemIndex].id === id
+ $api.activeItemIndex !== null
+ ? $api.items[$api.activeItemIndex].id === id
: false;
- $: buttonStore = $api?.buttonStore;
+ $: buttonStore = $api.buttonStore;
let elementRef: HTMLDivElement | undefined;
$: textValue = elementRef?.textContent?.toLowerCase().trim();
@@ -22,7 +22,7 @@
onMount(async () => {
await tick();
- $api?.registerItem(id, data);
+ $api.registerItem(id, data);
});
onDestroy(() => {
diff --git a/src/lib/components/menu/MenuItems.svelte b/src/lib/components/menu/MenuItems.svelte
index 3e0d5ac..3e8bb06 100644
--- a/src/lib/components/menu/MenuItems.svelte
+++ b/src/lib/components/menu/MenuItems.svelte
@@ -12,8 +12,8 @@
const id = `headlessui-menu-items-${useId()}`;
let searchDebounce: ReturnType | null = null;
- $: buttonStore = $api?.buttonStore;
- $: itemsStore = $api?.itemsStore;
+ $: buttonStore = $api.buttonStore;
+ $: itemsStore = $api.itemsStore;
let openClosedState = useOpenClosed();
@@ -24,7 +24,7 @@
$: treeWalker({
container: $itemsStore,
- enabled: $api?.menuState === MenuStates.Open,
+ enabled: $api.menuState === MenuStates.Open,
accept(node) {
if (node.getAttribute("role") === "menuitem")
return NodeFilter.FILTER_REJECT;
diff --git a/src/lib/components/radio-group/RadioGroupOption.svelte b/src/lib/components/radio-group/RadioGroupOption.svelte
index 76b0291..4ce45be 100644
--- a/src/lib/components/radio-group/RadioGroupOption.svelte
+++ b/src/lib/components/radio-group/RadioGroupOption.svelte
@@ -20,15 +20,15 @@
let state = OptionState.Empty;
function updateOption(option: Option) {
- $api?.unregisterOption(option.id);
- $api?.registerOption(option);
+ $api.unregisterOption(option.id);
+ $api.registerOption(option);
}
$: updateOption({ id, element: optionRef, propsRef });
- onDestroy(() => $api?.unregisterOption(id));
+ onDestroy(() => $api.unregisterOption(id));
- $: isFirstOption = $api?.firstOption?.id === id;
- $: isDisabled = $api?.disabled || disabled;
- $: checked = $api?.value === value;
+ $: isFirstOption = $api.firstOption?.id === id;
+ $: isDisabled = $api.disabled || disabled;
+ $: checked = $api.value === value;
$: tabIndex = (() => {
if (isDisabled) return -1;
diff --git a/src/lib/components/tabs/Tab.svelte b/src/lib/components/tabs/Tab.svelte
index 2b0fa68..748f589 100644
--- a/src/lib/components/tabs/Tab.svelte
+++ b/src/lib/components/tabs/Tab.svelte
@@ -22,13 +22,13 @@
$: selected = myIndex === $api.selectedIndex;
function handleKeyDown(event: KeyboardEvent) {
- let list = $api?.tabs.filter(Boolean) as HTMLElement[];
+ let list = $api.tabs.filter(Boolean) as HTMLElement[];
if (event.key === Keys.Space || event.key === Keys.Enter) {
event.preventDefault();
event.stopPropagation();
- $api?.setSelectedIndex(myIndex);
+ $api.setSelectedIndex(myIndex);
return;
}
@@ -74,7 +74,7 @@
if (disabled) return;
tabRef?.focus();
- $api?.setSelectedIndex(myIndex);
+ $api.setSelectedIndex(myIndex);
}
$: propsWeControl = {