diff --git a/src/lib/components/listbox/Listbox.svelte b/src/lib/components/listbox/Listbox.svelte index eb28dd9..2aebe20 100644 --- a/src/lib/components/listbox/Listbox.svelte +++ b/src/lib/components/listbox/Listbox.svelte @@ -34,6 +34,22 @@ unregisterOption(id: string): void; select(value: unknown): void; }; + + const LISTBOX_CONTEXT_NAME = "ListboxContext"; + export function useListboxContext( + component: string + ): Writable { + let context: Writable | undefined = + getContext(LISTBOX_CONTEXT_NAME); + + if (context === undefined) { + throw new Error( + `<${component} /> is missing a parent component.` + ); + } + + return context; + }