Clean up Listbox store/context usage

Fixes #9
This commit is contained in:
Ryan Gossiaux
2021-12-18 23:07:55 -08:00
parent 1966219b30
commit 4d47ba89a6
5 changed files with 37 additions and 40 deletions

View File

@@ -8,6 +8,8 @@
let api = useListboxContext("ListboxOption");
let id = `headlessui-listbox-option-${useId()}`;
let buttonRef = $api.buttonRef;
$: active =
$api?.activeOptionIndex !== null
? $api?.options[$api.activeOptionIndex].id === id
@@ -62,7 +64,7 @@
$api.select(value);
$api.closeListbox();
await tick();
$api.buttonRef?.focus({ preventScroll: true });
$buttonRef?.focus({ preventScroll: true });
}
function handleFocus() {