import type { OpenDetail } from '../shared/events.js';
import { UiElement } from '../shared/element.js';
/** When chosen options move to the top of the list (Carbon `selectionFeedback`). */
export type SelectionFeedback = 'top-after-reopen' | 'top' | 'fixed';
/** How the text of a `filterable` multi select narrows the list; `none` leaves it to a server search. */
export type MultiSelectFilter = 'contains' | 'starts-with' | 'none';
/**
* Carbon-style multi select (Carbon `MultiSelect`, downshift useSelect + useMultipleSelection):
* a field that always shows its placeholder text, a count tag with a clear button once something
* is chosen, and a list of checkbox rows that stays open while choosing.
*
* - Options are `` children (`selected` marks initial choices); `value` is the
* array of chosen values. Submits one form entry per chosen value under `name`.
* - Keys as Carbon (React MultiSelect traced key by key): ↓ Enter Space open (↑ doesn't); while open
* ↓ ↑ PageUp PageDown Home End move, Enter / Space toggle the row (the list stays open), typing jumps
* to a match, Esc closes. Delete / Backspace / Esc on the closed field clear every choice. The ×
* buttons are no Tab stops (Carbon `tabindex="-1"`).
* - `selection-feedback`: chosen rows move to the top on the next open (`top-after-reopen`,
* default), at once (`top`) or never (`fixed`). Author order is kept otherwise — Carbon
* additionally sorts alphabetically; we don't, because ` ` order is the author's intent.
* With ` `s the groups stay as authored and nothing moves.
* - `select-all` adds a first row that checks / unchecks every enabled option (indeterminate in between).
* - `filterable` (Carbon `FilterableMultiSelect` / `cds-multi-select filterable`): the field is a text box
* that narrows the list as you type (`filter`: `contains`, Carbon's rule, or `starts-with`) and
* highlights the first row; × clears the text. Choosing keeps the text and the list open; Enter
* toggles the highlight (Space types a space), Esc closes and, on a closed list, clears the
* choices and the text; leaving the field clears the text. "Select all" acts on the rows shown.
* Clicking the text box opens the list but never closes it, and no match shows a "No matching
* items" row — both as ui-combobox (Carbon closes, and shows an empty list; user's choice).
* For a server search set `filter="none"`, listen to `ui-input`, fetch with its `value`, replace
* the options and toggle `loading`; keep chosen ``s in the list so their rows stay.
* - `loading` without `filterable` (no Carbon counterpart): one "Loading…" row instead of the
* options, busy and announced, the keys pick nothing; with `ui-toggle` an app can load the
* options the first time the list opens.
* - 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 at least one option
* is chosen (the count tag shows) (e.g. `ui-multi-select[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 - Whenever the set of chosen values changes
* @fires ui-toggle - detail: { open } after the list opens or closes (Carbon React `onMenuChange`)
* @fires input - Whenever the set of chosen values changes, as ui-dropdown and ui-combobox; with `filterable`, 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`) with `filterable`, as the user types or when the text is emptied
* @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 field button, or the text box with `filterable` (role=combobox)
* @csspart toggle - The chevron button (`filterable`)
* @csspart clear-filter-button - The × that clears the text (`filterable`)
* @csspart empty - The "searching" / "no results" row (`filterable`)
* @csspart tag - The selected-count pill
* @cssprop --ui-count-tag-background - The count pill's fill (default `--ui-ink`); also `--ui-count-tag-ink` (`--ui-inverse-ink`) and `--ui-count-tag-hover` (its ×, `--ui-secondary-hover`)
* @csspart clear-button - The × inside the pill
* @csspart chevron - The arrow icon
* @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 select-all - The "Select all" row
* @csspart checkbox - The box drawn in each row
* @csspart group-label - An ` ` heading
* @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-field-open-background - The box's fill while its list is open (default the field's hover fill; Kanok: transparent)
* @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-option-box-align / --ui-option-box-offset - A two-line row's checkbox: `align-self` and top margin (default auto, 0: centred; Kanok: beside the label line)
* @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)
* @cssprop --ui-focus-offset - `outline-offset` of its focus ring (default -2px: inside; Kanok: 2px outside)
*/
export declare class UiMultiSelect 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;
/** Text always shown in the field (Carbon's `label`), e.g. "Choose options". */
placeholder: string;
/** Chosen option values. Initial choices can also come from ``. */
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';
selectionFeedback: SelectionFeedback;
/** Adds a "Select all" row. */
selectAll: boolean;
/** The field is a text box that narrows the list (Carbon `FilterableMultiSelect` / `filterable`). */
filterable: boolean;
/** With `filterable`: `contains` (Carbon), `starts-with`, or `none` to leave the list to a server search. */
filter: MultiSelectFilter;
/** The options are on their way: "Searching…" with `filterable` (a server search), else "Loading…"; the keys pick nothing. */
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 `FluidMultiSelect`: the label inside a 64px box, an error / warning inside it. `` sets it for every field inside. */
fluid: boolean;
private groups;
private options;
private open;
/** Highlighted row: index into the displayed rows, SELECT_ALL for the first row, -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;
/** Values that were chosen when the list last opened (for `top-after-reopen`). */
private pinned;
/** Text typed into a `filterable` field. */
private text;
private readonly trigger;
private readonly input;
private readonly field;
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 readonly typed;
/** With `filterable`, what the user typed; set it to search for something. */
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 hands the saved values 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();
private isChosen;
/** The typed text narrows the list (`filterable`, a filter other than `none`, some text). */
private get filtering();
private isShown;
/** The groups shown: as authored, narrowed by the typed text. */
private get shownGroups();
/** Rows in display order: chosen ones first per `selection-feedback`, author order otherwise; narrowed by the typed text. */
private get rows();
/** Enabled options "Select all" acts on: the rows shown (Carbon, filterable). */
private get enabledOptions();
/** The "Select all" row shows while it has rows to act on (Carbon hides it when the filter leaves none). */
private get showSelectAll();
/** 'all' | 'some' | 'none' of the enabled options are chosen. */
private get selectAllState();
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;
/** The highlight once the rows changed from `before` (core reconcileActive); "Select all" stays while it shows. */
private reconciled;
/** Rows in display order, grouped only when ``s are authored; "Searching…" / "No matching items" while filterable. */
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 openMenu;
private close;
/** Carbon filterable: closing by a click or leaving the field drops the typed text. */
private closeAndClearText;
/** Empties the typed text; fires `ui-input` (and `input`) like typing would, so a server search can reset its options. */
private resetText;
private emitTyping;
/** Mouse: Carbon highlights the first chosen row, or nothing when none is chosen (the keyboard starts on the first row). */
private toggle;
private readonly reposition;
private onOpenChanged;
private stopTracking?;
private stopOutside?;
private removeMenuListeners;
private position;
private scrollActiveIntoView;
private readonly onDocumentPointerDown;
private onTriggerFocusOut;
/** `input` means "the value changed" with or without `filterable`; the typing has `ui-input`. */
private setValue;
private toggleOption;
private toggleSelectAll;
private toggleActive;
private clearAll;
private firstEnabled;
/** The button's keys (core/multi-select, Carbon MultiSelect traced key by key). */
private onTriggerKeydown;
private apply;
/** The text box's keys (core/multi-select, Carbon FilterableMultiSelect). */
private onFilterKeydown;
/** Typing narrows the list, opens it and highlights the first row (Carbon). */
private onFilterInput;
/** As ui-combobox: a click opens the list (highlighting the first chosen row, or nothing) and never closes it. */
private onFilterClick;
private onToggleClick;
private clearText;
/** Focus leaving the field (the text box, × or the tag's ×, not to one of them) closes the list and drops the text (Carbon). */
private onFilterFocusOut;
private renderBox;
private renderSelectAllRow;
private renderRow;
/** With `filterable`, the tag's × doesn't take focus, so the text box keeps it. */
private readonly onTagButtonMousedown;
private renderTag;
private readonly slots;
private renderLabel;
private activeId;
/** The trigger always shows the placeholder, so the selected count (and any message) describes it. */
private describedBy;
private renderTrigger;
/** `filterable`: count tag, text box, then status / × / chevron as ui-combobox. */
private renderFilterField;
private renderClearText;
private get showClearText();
/** The field's state classes: invalid, status icon, tags, open, filterable, clear button, disabled. */
private fieldClasses;
private get showError();
/** The one message line: error > warning > helper. */
private get fieldMessage();
render(): import("lit-html").TemplateResult<1>;
}
export interface UiMultiSelectEventMap extends HTMLElementEventMap {
'ui-toggle': CustomEvent;
'ui-input': CustomEvent<{
value: string;
}>;
}
/** Typed listeners for UiMultiSelect's events (declaration merging with the class). */
export interface UiMultiSelect {
addEventListener(type: K, listener: (this: UiMultiSelect, event: UiMultiSelectEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener(type: K, listener: (this: UiMultiSelect, event: UiMultiSelectEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void;
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
}
declare global {
interface HTMLElementTagNameMap {
'ui-multi-select': UiMultiSelect;
}
}