/* * 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/5c1920e50d4b2b80c826ca91aff55c97350bf9f9/packages/@react-aria/select/src/useSelect.ts */ import { OverrideComponentProps, type ValidationState, access, createGenerateId, focusWithoutScrolling, 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 { createCollator } from "../i18n"; import { ListKeyboardDelegate, createListState } from "../list"; import { type ElementOf, Polymorphic, type PolymorphicProps, } from "../polymorphic"; import { Popper, type PopperRootOptions } from "../popper"; import { type CollectionNode, createDisclosureState, createFormResetListener, createRegisterId, } from "../primitives"; import { type FocusStrategy, type KeyboardDelegate, Selection, type SelectionBehavior, type SelectionMode, } from "../selection"; import { SelectContext, type SelectContextValue, type SelectDataSet, } from "./select-context"; export interface SelectBaseItemComponentProps { /** The item to render. */ item: CollectionNode; } export interface SelectBaseSectionComponentProps { /** The section to render. */ section: CollectionNode; } export interface SelectBaseOptions extends Omit< PopperRootOptions, "anchorRef" | "contentRef" | "onCurrentPlacementChange" > { /** The controlled open state of the select. */ 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 select changes. */ onOpenChange?: (isOpen: boolean) => void; /** The controlled value of the select. */ value?: Option[]; /** * The value of the select 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 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