/* * Portions of this file are based on code from react-spectrum. * Apache License Version 2.0, Copyright 2020 Adobe. * * Credits to the React Spectrum team: * https://github.com/adobe/react-spectrum/blob/ba727bdc0c4a57626131e84d9c9b661d0b65b754/packages/@react-stately/combobox/src/useComboBoxState.ts * https://github.com/adobe/react-spectrum/blob/ba727bdc0c4a57626131e84d9c9b661d0b65b754/packages/@react-aria/combobox/src/useComboBox.ts */ import { type ValidationState, access, createGenerateId, focusWithoutScrolling, isAppleDevice, isFunction, mergeDefaultProps, } from "@kobalte/utils"; import { type Accessor, type Component, type JSX, type ValidComponent, createEffect, createMemo, createSignal, createUniqueId, on, splitProps, } from "solid-js"; import createPresence from "solid-presence"; import { FORM_CONTROL_PROP_NAMES, FormControlContext, type FormControlDataSet, createFormControl, } from "../form-control"; import { createFilter } from "../i18n"; import { ListKeyboardDelegate, createListState } from "../list"; import { announce } from "../live-announcer"; import { type ElementOf, Polymorphic, type PolymorphicProps, } from "../polymorphic"; import { Popper, type PopperRootOptions } from "../popper"; import { type CollectionNode, createControllableSignal, createDisclosureState, createFormResetListener, createRegisterId, getItemCount, } from "../primitives"; import { type FocusStrategy, type KeyboardDelegate, Selection, type SelectionBehavior, type SelectionMode, createSelectableCollection, } from "../selection"; import { ComboboxContext, type ComboboxContextValue, type ComboboxDataSet, } from "./combobox-context"; import { COMBOBOX_INTL_TRANSLATIONS, type ComboboxIntlTranslations, } from "./combobox.intl"; import type { ComboboxTriggerMode } from "./types"; export interface ComboboxBaseItemComponentProps { /** The section to render. */ section: CollectionNode; } export interface ComboboxBaseOptions extends Omit< PopperRootOptions, "anchorRef" | "contentRef" | "onCurrentPlacementChange" > { /** Prevents input reset on combobox blur when content is displayed. */ noResetInputOnBlur?: boolean; /** The localized strings of the component. */ translations?: ComboboxIntlTranslations; /** The controlled open state of the combobox. */ open?: boolean; /** * The default open state when initially rendered. * Useful when you do not need to control the open state. */ defaultOpen?: boolean; /** * Event handler called when the open state of the combobox changes. * Returns the new open state and the action that caused the opening of the menu. */ onOpenChange?: (isOpen: boolean, triggerMode?: ComboboxTriggerMode) => void; /** Handler that is called when the combobox input value changes. */ onInputChange?: (value: string) => void; /** The controlled value of the combobox. */ value?: Option[]; /** * The value of the combobox when initially rendered. * Useful when you do not need to control the value. */ defaultValue?: Option[]; /** Event handler called when the value changes. */ onChange?: (value: Option[]) => void; /** The interaction required to display the combobox menu. */ triggerMode?: ComboboxTriggerMode; /** The content that will be rendered when no value or defaultValue is set. */ placeholder?: JSX.Element; /** An array of options to display as the available options. */ options: Array