diff --git a/src/lib/components/listbox/Listbox.svelte b/src/lib/components/listbox/Listbox.svelte
index 896abfe..e9e0616 100644
--- a/src/lib/components/listbox/Listbox.svelte
+++ b/src/lib/components/listbox/Listbox.svelte
@@ -61,6 +61,17 @@
import { Readable, writable, Writable } from "svelte/store";
import { match } from "$lib/utils/match";
import { State, useOpenClosedProvider } from "$lib/internal/open-closed";
+ import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
+ import { get_current_component } from "svelte/internal";
+ import type { SupportedAs } from "$lib/internal/elements";
+ import type { HTMLActionArray } from "$lib/hooks/use-actions";
+ import Render from "$lib/utils/Render.svelte";
+ const forwardEvents = forwardEventsBuilder(get_current_component(), [
+ "change",
+ ]);
+ export let as: SupportedAs = "div";
+ export let use: HTMLActionArray = [];
+
export let disabled = false;
export let horizontal = false;
export let value: StateDefinition["value"];
@@ -205,7 +216,16 @@
$buttonRef?.focus({ preventScroll: true });
}
}
+ $: slot = { open: listboxState === ListboxStates.Open };
-
+
+
+
diff --git a/src/lib/components/listbox/ListboxButton.svelte b/src/lib/components/listbox/ListboxButton.svelte
index 23c133d..94229ff 100644
--- a/src/lib/components/listbox/ListboxButton.svelte
+++ b/src/lib/components/listbox/ListboxButton.svelte
@@ -4,6 +4,15 @@
import { useId } from "$lib/hooks/use-id";
import { Keys } from "$lib/utils/keyboard";
import { Focus } from "$lib/utils/calculate-active-index";
+ import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
+ import type { SupportedAs } from "$lib/internal/elements";
+ import type { HTMLActionArray } from "$lib/hooks/use-actions";
+ import { get_current_component } from "svelte/internal";
+ import Render from "$lib/utils/Render.svelte";
+
+ const forwardEvents = forwardEventsBuilder(get_current_component());
+ export let as: SupportedAs = "button";
+ export let use: HTMLActionArray = [];
let api = useListboxContext("ListboxButton");
let id = `headlessui-listbox-button-${useId()}`;
@@ -11,7 +20,8 @@
let optionsRef = $api.optionsRef;
let labelRef = $api.labelRef;
- async function handleKeyDown(event: KeyboardEvent) {
+ async function handleKeyDown(e: CustomEvent) {
+ let event = e as any as KeyboardEvent;
switch (event.key) {
// Ref: https://www.w3.org/TR/wai-aria-practices-1.2/#keyboard-interaction-13
case Keys.Space:
@@ -34,7 +44,8 @@
}
}
- function handleKeyUp(event: KeyboardEvent) {
+ function handleKeyUp(e: CustomEvent) {
+ let event = e as any as KeyboardEvent;
switch (event.key) {
case Keys.Space:
// Required for firefox, event.preventDefault() in handleKeyDown for
@@ -45,7 +56,8 @@
}
}
- async function handleClick(event: MouseEvent) {
+ async function handleClick(e: CustomEvent) {
+ let event = e as any as MouseEvent;
if ($api.disabled) return;
if ($api.listboxState === ListboxStates.Open) {
$api.closeListbox();
@@ -69,18 +81,24 @@
"aria-labelledby": $labelRef ? [$labelRef?.id, id].join(" ") : undefined,
disabled: $api.disabled === true ? true : undefined,
};
+
+ $: slot = {
+ open: $api.listboxState === ListboxStates.Open,
+ disabled: $api.disabled,
+ };
-
+
+
diff --git a/src/lib/components/listbox/ListboxLabel.svelte b/src/lib/components/listbox/ListboxLabel.svelte
index 7be27ba..2402dcd 100644
--- a/src/lib/components/listbox/ListboxLabel.svelte
+++ b/src/lib/components/listbox/ListboxLabel.svelte
@@ -1,6 +1,16 @@
-
-
+
+
+
diff --git a/src/lib/components/listbox/ListboxOption.svelte b/src/lib/components/listbox/ListboxOption.svelte
index 5e3bb5d..c41a69d 100644
--- a/src/lib/components/listbox/ListboxOption.svelte
+++ b/src/lib/components/listbox/ListboxOption.svelte
@@ -3,6 +3,16 @@
import { ListboxStates, useListboxContext } from "./Listbox.svelte";
import { useId } from "$lib/hooks/use-id";
import { Focus } from "$lib/utils/calculate-active-index";
+ import Render from "$lib/utils/Render.svelte";
+ import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
+ import type { SupportedAs } from "$lib/internal/elements";
+ import { get_current_component } from "svelte/internal";
+ import type { HTMLActionArray } from "$lib/hooks/use-actions";
+
+ const forwardEvents = forwardEventsBuilder(get_current_component());
+ export let as: SupportedAs = "li";
+ export let use: HTMLActionArray = [];
+
export let value: unknown;
export let disabled = false;
let api = useListboxContext("ListboxOption");
@@ -59,7 +69,8 @@
}
$: updateFocus($api.listboxState, selected, active);
- async function handleClick(event: MouseEvent) {
+ async function handleClick(e: CustomEvent) {
+ let event = e as any as MouseEvent;
if (disabled) return event.preventDefault();
$api.select(value);
$api.closeListbox();
@@ -92,17 +103,16 @@
"aria-selected": selected === true ? selected : undefined,
};
- $: classStyle = $$props.class
- ? typeof $$props.class === "function"
- ? $$props.class({ active, selected, disabled })
- : $$props.class
- : "";
+ $: slot = { active, selected, disabled };
-
-
-
+
+
diff --git a/src/lib/components/listbox/ListboxOptions.svelte b/src/lib/components/listbox/ListboxOptions.svelte
index e330413..8d1d58b 100644
--- a/src/lib/components/listbox/ListboxOptions.svelte
+++ b/src/lib/components/listbox/ListboxOptions.svelte
@@ -6,6 +6,15 @@
import { Keys } from "$lib/utils/keyboard";
import { Focus } from "$lib/utils/calculate-active-index";
import { State, useOpenClosed } from "$lib/internal/open-closed";
+ import Render from "$lib/utils/Render.svelte";
+ import { forwardEventsBuilder } from "$lib/internal/forwardEventsBuilder";
+ import type { SupportedAs } from "$lib/internal/elements";
+ import type { HTMLActionArray } from "$lib/hooks/use-actions";
+ import { get_current_component } from "svelte/internal";
+
+ const forwardEvents = forwardEventsBuilder(get_current_component());
+ export let as: SupportedAs = "ul";
+ export let use: HTMLActionArray = [];
let api = useListboxContext("ListboxOptions");
let id = `headlessui-listbox-options-${useId()}`;
@@ -14,7 +23,8 @@
let labelRef = $api.labelRef;
let searchDebounce: ReturnType | null = null;
- async function handleKeyDown(event: KeyboardEvent) {
+ async function handleKeyDown(e: CustomEvent) {
+ let event = e as any as KeyboardEvent;
if (searchDebounce) clearTimeout(searchDebounce);
switch (event.key) {
@@ -106,15 +116,21 @@
usesOpenClosedState !== undefined
? $usesOpenClosedState === State.Open
: $api.listboxState === ListboxStates.Open;
+
+ $: slot = { open: $api.listboxState === ListboxStates.Open };
{#if visible}
-
+
+
{/if}