import { type ComponentProps, type ReactNode, type RefObject } from 'react'; import { type ComboStep } from '../core/combobox.js'; import type { TextFilter } from '../core/listbox.js'; import { type ListItem, type ListOption } from './list-items.js'; import { type ListPopupProps } from './list-parts.tsx'; /** * Unstyled Carbon `ComboBox` (APG editable combobox with list autocomplete), the behaviour of the * styled Combobox without a single class: an `Input` with `role="combobox"`; typing highlights the * first option containing the text (and, with `filter`, narrows the list); Enter picks the * highlight (or the first option containing the text); leaving the field commits an exact match, * keeps free text with `allowCustomValue`, else snaps back; Esc closes, then clears. `Clear` empties * text and value and keeps focus; `Toggle` opens and closes; neither is a Tab stop. The options are * data on `Root` (`items`); `Popup` hands its render function the ones the text keeps. * * State shows as data attributes to style on: `data-open`, `data-disabled`, `data-readonly`, * `data-invalid` on the `Input`, `data-open` on `Toggle` and `Popup`, and on options * `data-highlighted`, `data-selected`, `data-disabled`. The popup lines up with `Anchor` (the box * around the input and its buttons), or the `Input` when there is none. * * ```tsx * * * ▾ * {(items) => items.map((f) => 'options' in f ? null : {f.label})} * * ``` */ export interface RootProps { /** Options, and groups of options (`{ label, options }`). */ items: ListItem[]; value?: string; defaultValue?: string; /** After the value changes (a pick, a committed text, a clear). */ onValueChange?: (value: string) => void; /** Every keystroke (e.g. to search a server; with `filter="none"` the list is yours to fill); with `inputValue`, every other change of the text too. */ onInputValueChange?: (text: string) => void; /** The text box's text, controlled (Lit `inputValue`): a pick, a clear and the snap-back on leaving are reported through `onInputValueChange`. */ inputValue?: string; /** How typed text narrows the list; `none` (default) only highlights, as Carbon. */ filter?: TextFilter; /** Keep text that matches no option as the value. */ allowCustomValue?: boolean; /** The options are on their way (a server search): the popup is `aria-busy`. */ loading?: boolean; /** After the list opened or closed. */ onOpenChange?: (open: boolean) => void; disabled?: boolean; readOnly?: boolean; required?: boolean; /** Marks the input `aria-invalid` and `data-invalid`. */ invalid?: boolean; /** * A submit attempt (or `reportValidity()`) found it `required` with nothing chosen: show the error (the form is * blocked and the field takes the focus). Not called for `checkValidity()`, which stays silent. */ onInvalid?: () => void; /** Submits the value with the form (a hidden input), unless disabled. */ name?: string; /** * The input's id, and the base of the other parts' ids (`-list`, `-opt-`); generated when left out. * There is no Label part: the popup's `aria-labelledby` points at `-label`, so give your `