feature/search-select-search-in-trigger
This commit is contained in:
33
frontend/src/lib/components/ui/select/select-root.svelte
Normal file
33
frontend/src/lib/components/ui/select/select-root.svelte
Normal file
@@ -0,0 +1,33 @@
|
||||
<script lang="ts">
|
||||
import { Select as SelectPrimitive } from "bits-ui";
|
||||
import { writable } from "svelte/store";
|
||||
import { setContext } from "svelte";
|
||||
import { selectSearchContextKey, type SelectSearchContext } from "./select-search-context";
|
||||
import { type WithoutChild } from "$lib/utils.js";
|
||||
|
||||
let { children, ...restProps }: WithoutChild<SelectPrimitive.RootProps> = $props();
|
||||
|
||||
let open = $state(false);
|
||||
const query = writable("");
|
||||
const openStore = writable(false);
|
||||
const context: SelectSearchContext = {
|
||||
query,
|
||||
open: openStore,
|
||||
setOpen: (next) => {
|
||||
open = next;
|
||||
}
|
||||
};
|
||||
|
||||
setContext(selectSearchContextKey, context);
|
||||
|
||||
$effect(() => {
|
||||
openStore.set(open);
|
||||
if (!open) {
|
||||
query.set("");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<SelectPrimitive.Root bind:open {...restProps}>
|
||||
{@render children?.()}
|
||||
</SelectPrimitive.Root>
|
||||
Reference in New Issue
Block a user