import type { OpenDetail } from '../shared/events.js';
import { UiElement } from '../shared/element.js';
/** How typed text narrows the list. Carbon shows every item unless a filter is given (`none`). */
export type ComboboxFilter = 'none' | 'contains' | 'starts-with';
/**
* Carbon-style combo box: a text box with a filterable list (Carbon `ComboBox`, built on
* downshift's useCombobox). The counterpart of ui-dropdown for long lists, searching and
* server-side lookups.
*
* - Options are `` children (optionally in ` `), like ui-select / ui-dropdown. For a server search,
* listen to `ui-input` on the host, fetch with its `value` (`inputValue`), re-render the options and toggle
* `loading`; the list shows "Searching…" / "No matching items" rows meanwhile.
* - `filter`: `none` (Carbon default — all options stay visible), `contains` or `starts-with`.
* - Keys as Carbon (React ComboBox traced key by key; cds-combo-box agrees on typing): typing opens
* the list and highlights the first option containing the text. ↓ / ↑ open (↑ on the last option)
* and move the highlight (no wrap), Alt+↓ opens without a highlight, Alt+↑ picks the highlight and
* closes. Enter picks the highlight, or — with no highlight — the first option containing the
* text; Esc closes, and when already closed clears the field. Tab / blur don't pick the highlight
* (Carbon): an exact match is committed, otherwise the text snaps back to the selected option
* unless `allow-custom-value` lets free text stand.
* - Clicking the text box opens the list (never closes it); the chevron toggles; × clears. Neither
* button takes focus or a Tab stop (Carbon `tabindex="-1"`): Esc on a closed list clears from
* the keyboard. `hide-clear` drops × (not in Carbon, which always shows it).
* - Form-associated: submits `value` (the option's value, or the free text with
* `allow-custom-value`); honours `required`. `readonly` keeps and submits the value.
* - State on the host for app styles: `data-open` while the list is open, `data-show-error` /
* `data-show-warn` while the error / warning line shows, `data-has-value` while the box holds text
* (e.g. `ui-combobox[data-open]::part(base)`).
*
* @cssstate open - While its list or calendar is open (also `[data-open]`)
* @cssstate show-error - While its error message shows (also `[data-show-error]`)
* @cssstate show-warn - While its warning message shows (also `[data-show-warn]`)
* @cssstate has-value - While it holds a value (also `[data-has-value]`)
* @fires change - When the committed value changes
* @fires input - Whenever `value` changes, as ui-dropdown and ui-multi-select; also native and composed as the user types, where `value` is unchanged (kept for compatibility: listen to `ui-input` for the typing)
* @fires ui-input - detail: { value } the typed text (`inputValue`), as the user types
* @fires ui-toggle - detail: { open } after the list opens or closes
* @slot label - Label content with markup; the `label` attribute is the plain-text fallback
* @slot helper-text - Helper text with markup (links, bold); overrides `helper-text`
* @slot warn-text - Warning text shown while `warn`; overrides `warn-text`
* @slot invalid-text - Error text shown while invalid; overrides `invalid-text`
* @csspart option-description - Second line of an option (``)
* @csspart base - The field box
* @csspart label - The label
* @csspart input - The text box (role=combobox)
* @csspart clear-button - The × button
* @csspart toggle - The chevron button
* @csspart status-icon - The error / warning icon
* @csspart helper-text - The helper line
* @csspart warning-text - The warning line
* @csspart warn-text - Same line as `warning-text` (named after the `warn-text` attribute / slot)
* @csspart error-text - The error line
* @csspart invalid-text - Same line as `error-text` (named after the `invalid-text` attribute / slot)
* @csspart menu - The floating list
* @csspart option - Each row
* @csspart group-label - An ` ` heading
* @csspart empty - The "searching" / "no results" row
* @cssprop --ui-field-border - Border on every side of the box (default none: Carbon's underline only; Kanok: a 1px outline)
* @cssprop --ui-field-disabled-border-color - Border colour when disabled (default: the underline transparent)
* @cssprop --ui-field-readonly-border-color - Border colour when read-only (default: a hairline underline)
* @cssprop --ui-field-radius - Corner radius of the box (default 0; Kanok: 6px)
* @cssprop --ui-field-background - Fill of the box (default `--ui-surface-1`; Kanok: transparent)
* @cssprop --ui-label-font - Font of the label (default `--ui-font-caption`; Kanok: 14px semibold)
* @cssprop --ui-label-color - Colour of the label (default `--ui-ink-muted`; Kanok: `--ui-ink`)
* @cssprop --ui-menu-radius - Corner radius of the open list (default 0; Kanok: 8px)
* @cssprop --ui-menu-border - Border around the list (default none; Kanok: a hairline)
* @cssprop --ui-menu-shadow - `box-shadow` of the list (default Carbon's 0 2px 6px)
* @cssprop --ui-menu-padding - Padding of the open list (default 0; Kanok: 4px, rows inset)
* @cssprop --ui-menu-item-radius - Corner radius of a row (default 0; Kanok: 6px)
* @cssprop --ui-menu-item-ink - Text of a row at rest (default `--ui-ink-muted`; Kanok: `--ui-ink`)
* @cssprop --ui-menu-divider - Rule between rows (default `--ui-row-divider`; Kanok: none)
* @cssprop --ui-menu-item-selected - Fill of the chosen row (default `--ui-surface-2`; Kanok: `--ui-highlight`)
* @cssprop --ui-menu-item-selected-hover - The chosen row under the pointer (default `--ui-layer-selected-hover`; Kanok: the highlight a shade deeper)
* @cssprop --ui-field-readonly-background - The box's fill when read-only (default transparent; Kanok: a faint ink tint, so read-only reads as set and never weaker than disabled)
* @cssprop --ui-fluid-background / --ui-fluid-gap - A fluid box's fill and the space under it (default the layer's fill, 0: boxes that touch; Kanok: transparent, 8px)
* @cssprop --ui-menu-item-active-outline / --ui-menu-item-active-background - The keyboard-highlighted row: its ring and its fill (default focus, transparent)
* @cssprop --ui-icon-control-radius - Corners of its small icon buttons, their hover fill and ring (default 0; Kanok: round)
* @cssprop --ui-menu-item-pressed - Fill of a pressed option (default `--ui-surface-2`; Kanok: the 20% pressed tint)
*/
export declare class UiCombobox extends UiElement {
static hostStates: readonly string[];
static readonly formAssociated = true;
static readonly shadowRootOptions: ShadowRootInit;
static readonly styles: import("lit").CSSResult[];
/** Visible label text; the `label` slot replaces it when markup is needed. */
label: string;
/** Keep the label for screen readers but don't show it. */
hideLabel: boolean;
/** Helper text under the field, shown while there is no error or warning. */
helperText: string;
/** Error text shown while `invalid` or while the field fails validation. */
invalidText: string;
/** Forces the error state, e.g. after server-side validation. */
invalid: boolean;
/** Non-blocking warning; shown when there is no error. */
warn: boolean;
/** Text of the warning shown while `warn`. */
warnText: string;
placeholder: string;
/** Committed value: the chosen option's value, or free text with `allow-custom-value`. */
value: string;
/** Reflected: form-associated elements submit under the `name` attribute. */
name: string;
/** Field height: sm 32px, md 40px, lg 48px (tokens `--ui-field-height-*`). */
size: 'sm' | 'md' | 'lg';
/** Preferred side for the list; it flips when there is no room. */
direction: 'bottom' | 'top';
filter: ComboboxFilter;
/** Keep text that matches no option as the value instead of snapping back. */
allowCustomValue: boolean;
/** No × button (Carbon always shows one while there is text); Escape on a closed list still clears. */
hideClear: boolean;
/** Shows a "Searching…" row while a server lookup is running. */
loading: boolean;
/** Disables the control; a disabled `` ancestor does the same. */
disabled: boolean;
/** Blocks form submission while the field is empty. */
required: boolean;
/** Shows and submits the value but blocks changes. */
readonly: boolean;
/** Carbon `FluidComboBox`: the label inside a 64px box, an error / warning inside it. `` sets it for every field inside. */
fluid: boolean;
private groups;
private options;
private text;
private open;
/** Highlighted row, as an index into the filtered list; -1 = none. */
private activeIndex;
private touched;
/** Disabled, reset defaults, validation on submit and the name given from outside (shared by the form fields). */
private readonly formControl;
private readonly input;
private readonly menu;
/** Message from `setCustomValidity()`; '' = none. */
private customValidityMessage;
/** Like ` .setCustomValidity()`: a non-empty message makes the field invalid (and is shown as its error once touched) until cleared with ''. */
setCustomValidity(message: string): void;
private readonly localize;
private readonly fieldId;
/** Created on connect: there is no MutationObserver when Lit renders on the server. */
private observer?;
private defaultValue;
private lastSyncedValue;
/** The rows listed at the last update: where the highlight was before the options changed. */
private shownRows;
/** What the user currently sees in the text box. */
get inputValue(): string;
set inputValue(text: string);
connectedCallback(): void;
disconnectedCallback(): void;
get form(): HTMLFormElement | null;
get validationMessage(): string;
/** Whether the field takes part in constraint validation (not while disabled), as natively. */
get willValidate(): boolean;
/** The ``s that point at this field. */
get labels(): NodeList;
reportValidity(): boolean;
get validity(): ValidityState;
checkValidity(): boolean;
formResetCallback(): void;
/** Back/forward cache and autofill hand the saved value back here. */
formStateRestoreCallback(state: string | File | FormData | null): void;
/** From an ancestor ``; kept apart so it never overwrites the author's `disabled`. */
formDisabledCallback(disabled: boolean): void;
private get isDisabled();
private get interactive();
private get messages();
/** Text the box should show for the committed value. */
private get committedText();
/**
* Text still equal to the committed choice doesn't filter: opening the list to change a
* selection shows every option (MUI / React Aria behaviour; Carbon would show one row).
*/
private get filteredGroups();
private get filtered();
protected willUpdate(changed: Map): void;
protected updated(changed: Map): void;
/** Internal states as presence attributes on the host, so app styles can select them (same conditions as render). */
private syncHostState;
private syncValidity;
private readOptions;
private openMenu;
private close;
/** Closing without a pick: text that matches no option snaps back (Carbon), unless free text is allowed. */
private closeAndSettle;
private readonly reposition;
private onOpenChanged;
private stopTracking?;
private stopOutside?;
private removeMenuListeners;
private position;
private scrollActiveIntoView;
private readonly onDocumentPointerDown;
private setValue;
private selectOption;
/** Blur / toggle-close rules from Carbon's state reducer. */
private commitText;
private clear;
private selectedIndexIn;
/** The keyboard of core/combobox (Carbon ComboBox, traced key by key). */
private onKeydown;
private apply;
/** Carbon (downshift findHighlightedIndex): typing highlights the first enabled option that contains the text. */
private onInput;
/** Carbon (web components and React): a mouse opening highlights the chosen option, or nothing when none is chosen. */
private openFromPointer;
private onInputClick;
private onToggleClick;
/** Focus leaving the text box (Tab, or a click on something focusable): Carbon's InputBlur — an exact match or a snap back, never the highlight. */
private onFocusOut;
private onOptionClick;
private renderOption;
private renderCheck;
private renderRows;
/** "Searching…" / "No matching items" for screen readers: the disabled rows in the list are never announced (WCAG 4.1.3). */
private get statusText();
private renderClear;
private readonly slots;
private renderLabel;
private fieldClasses;
private get showError();
/** The one message line: error > warning > helper. */
private get fieldMessage();
/** × shows: there is text and the field can change. */
private get showClear();
render(): import("lit-html").TemplateResult<1>;
}
export interface UiComboboxEventMap extends HTMLElementEventMap {
'ui-toggle': CustomEvent;
'ui-input': CustomEvent<{
value: string;
}>;
}
/** Typed listeners for UiCombobox's events (declaration merging with the class). */
export interface UiCombobox {
addEventListener(type: K, listener: (this: UiCombobox, event: UiComboboxEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener(type: K, listener: (this: UiCombobox, event: UiComboboxEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}
declare global {
interface HTMLElementTagNameMap {
'ui-combobox': UiCombobox;
}
}