/** * createAutocomplete - the HEADLESS core behind : a free-text * field with a live-filtered suggestion list (accepts ANY typed value; the * suggestions are shortcuts). Roving active index + keyboard, exposed as * **prop-getters** you spread onto YOUR OWN markup. No styles/DOM/portal - those * stay in the styled component. * * ```svelte * * * {#if ac.open} * * {/if} * ``` */ import { type ListOption } from './list-option'; /** Reactive inputs are passed as getters so the core tracks live prop changes. */ export type AutocompleteConfig = { value: () => string; onChange?: (value: string) => void; /** Suggestions - strings or {value,label} (label shown, value inserted). */ suggestions: () => ReadonlyArray; minChars?: () => number; disabled?: () => boolean; ariaLabel?: () => string | undefined; /** DOM focus hook provided by the renderer; the core never touches the DOM. */ focusInput?: () => void; id?: () => string | undefined; invalid?: () => boolean; required?: () => boolean; error?: () => string | undefined; hint?: () => string | undefined; }; export declare function createAutocomplete(config: AutocompleteConfig): { /** Panel open state. */ readonly open: boolean; /** Highlighted suggestion index into `filtered`. */ readonly activeIndex: number; /** Suggestions after the live substring filter (capped at 10). */ readonly filtered: ListOption[]; /** Controlled text value. */ readonly value: string; /** id of the listbox element (matches inputProps `aria-controls`). */ listId: string; isActive: (i: number) => boolean; setActive: (i: number) => void; maybeOpen: () => void; close: () => void; pick: (o: ListOption | undefined) => void; onInput: (e: Event) => void; onKeydown: (e: KeyboardEvent) => void; /** Spread onto the text . */ inputProps: () => { value: string; disabled: boolean; oninput: (e: Event) => void; onfocus: () => void; onkeydown: (e: KeyboardEvent) => void; 'aria-invalid': "true" | undefined; 'aria-required': "true" | undefined; 'aria-describedby': string | undefined; 'aria-label': string | undefined; id: string | undefined; role: "combobox"; 'aria-expanded': boolean; 'aria-controls': string; 'aria-autocomplete': "list"; 'aria-activedescendant': string | undefined; }; /** Spread onto the listbox container. */ listboxProps: () => { id: string; role: "listbox"; }; /** Spread onto the suggestion at `index` (index into `filtered`). */ optionProps: (index: number) => { id: string; role: "option"; tabindex: number; 'aria-selected': boolean; 'data-idx': number; onclick: () => void; onpointermove: () => void; }; }; export type Autocomplete = ReturnType;