import { type Accessor, createContext, useContext } from "solid-js"; import type { AutocompleteMode } from "./autocomplete-root"; /** * Autocomplete-specific context layered on top of the combobox root * context. Carries bits that combobox doesn't know about — currently * just the `mode`, which drives `aria-autocomplete` on the input and * the `data-*` attributes on the input-group. * * The bulk of shared state (open, inputValue, indices, refs, etc.) * still flows through `ComboboxRootContext` so that every * combobox-provided sub-part (Portal, Positioner, Popup, List, etc.) * works against an autocomplete root without rewiring. */ export interface AutocompleteRootContextValue { mode: Accessor; } export const AutocompleteRootContext = createContext(null); export function useAutocompleteRootContext(): AutocompleteRootContextValue; export function useAutocompleteRootContext( optional: true, ): AutocompleteRootContextValue | null; export function useAutocompleteRootContext( optional?: boolean, ): AutocompleteRootContextValue | null { const ctx = useContext(AutocompleteRootContext); if (ctx == null && !optional) { throw new Error( "Base UI: AutocompleteRootContext is missing. Autocomplete parts must be placed within .", ); } return ctx; }