Files
eewing ec317eb17c
CI / build (push) Has been skipped
CI / deploy (push) Successful in 1m11s
INIT
2026-02-18 15:17:47 -06:00

42 lines
1.0 KiB
Svelte

<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { ComboboxInputProps } from "../types.js";
import { useId } from "../../../internal/use-id.js";
import { FloatingLayer } from "../../utilities/floating-layer/index.js";
import { SelectInputState } from "../../select/select.svelte.js";
let {
id = useId(),
ref = $bindable(null),
child,
defaultValue,
clearOnDeselect = false,
...restProps
}: ComboboxInputProps = $props();
const inputState = SelectInputState.create({
id: boxWith(() => id),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
clearOnDeselect: boxWith(() => clearOnDeselect),
});
if (defaultValue) {
inputState.root.opts.inputValue.current = defaultValue;
}
const mergedProps = $derived(
mergeProps(restProps, inputState.props, { value: inputState.root.opts.inputValue.current })
);
</script>
<FloatingLayer.Anchor {id} ref={inputState.opts.ref}>
{#if child}
{@render child({ props: mergedProps })}
{:else}
<input {...mergedProps} />
{/if}
</FloatingLayer.Anchor>