UNPKG

@llselect/core

Version:

Low-level select: a minimal, flexible, framework-agnostic replacement for the native HTML select element.

821 lines • 44.6 kB
import { LLSelectBase, type LLSelectBaseSettings, type LLSelectBeforeChangeEvent, type LLSelectChangeMeta, type LLSelectSettingsInputOf } from './base.js'; /** * Trigger display mode of {@link LLSelectMultiple}. * - `'count'`: a text summary like "3 / 10 selected". * - `'tags'`: one removable chip per chosen item. * See {@link LLSelectMultipleSettings.triggerDisplay}. * @group Settings * @category Multiple */ export type LLSelectTriggerDisplay = 'count' | 'tags'; /** * Tri-state of the choose-all row (also the `data-chosen-state` attribute * value): how much of the VISIBLE enabled subset is currently chosen. * @group Settings * @category Multiple */ export type LLSelectChosenState = 'none' | 'some' | 'all'; /** * Order of the chosen items, as tags, `getChosenItems`, `onChange` and a * framework model see them. See `LLSelectMultipleSettings.chosenItemsOrder`. * @group Settings * @category Multiple */ export type LLSelectChosenItemsOrder = 'as-chosen' | 'as-listed'; /** * Context passed to {@link LLSelectMultipleSettings.createTriggerContentElFn} * and {@link LLSelectMultipleSettings.triggerContextToScreenReaderTextFn}. * @group Settings * @category Multiple */ export interface LLSelectMultipleTriggerContext<T> { chosenItems: readonly T[]; items: readonly T[]; } /** * Resolved (defaults applied) settings for {@link LLSelectMultiple}: the base * settings plus the multi-mode fields - the runtime type of `this.settings`, * one bag built complete in the constructor. * @group Settings * @category Multiple */ export interface LLSelectMultipleSettings<T, GroupKey = string> extends LLSelectBaseSettings<T, GroupKey> { /** * Fired **after** the chosen-items set actually changed. Receives the new set * and the PREVIOUS one (the snapshot from before this change) - diff them * with `compareFn` to compute added / removed. Does NOT fire on * construction nor on a setter call that yields an equivalent set * (element-wise compared via `compareFn`, order-sensitive). * `null` (default) = no listener. * * > Pairs with `onBeforeChange`, which runs **before** a user change and can stop it. * * - When `chosenItemsOrder` is `'as-listed'`, the order is normalized first, * so a same-set write in another order is no change for items the list * holds. * - When `chosenItemsOrder` is `'as-listed'`, unlisted items go last, * keeping their order relative to each other, so reordering them is a * change. * - `meta.source` says who initiated the change: `'user'` for a pointer or * keyboard interaction inside the select component (an option toggle, a * tag's remove button, the clear button, the choose-all row, an action * row's `onActivate`), `'api'` for any programmatic call. See * {@link LLSelectChangeMeta}. * - `meta.reason` says what the change did: `'choose'` or `'unchoose'` * with the one toggled item in `meta.item`, `'clear'` for an empty * whole-value write or an emptying bulk op, `'set'` for a whole-value * write with items or a bulk op whose result is not empty, `'items'` * for a `setItems` reconciliation. See {@link LLSelectChangeReason}. * - Runs **after** the value changed and the trigger was updated. * - `getChosenItems()` already returns the new value. * - A setter may be called from inside it. The nested `onChange` then * reports `meta.source` `'api'`. * - A modal dialog may be opened, or focus moved, from inside it. * - Focus that already moved outside the select component is not reclaimed. * - Moving focus outside the select component closes the popup, as always. * @group Events */ onChange: ((chosenItems: readonly T[], previousChosenItems: readonly T[], meta: LLSelectChangeMeta<T>) => void) | null; /** * Fired **before** a user interaction changes the chosen items, with a way to * stop it. * * > Pairs with `onChange`, which runs **after** the change was written. * * - Fires for the library's own pointer and keyboard paths only: a row * toggle in the popup, a tag chip's remove button, the clear button, the * choose-all row. Programmatic setters, the `setItems` reconciliation and * an action row's own setter calls never fire it. * - `nextChosenItems` is the list about to be set. `previousChosenItems` * is the current one. * - `event.reason` and `event.item` say what the change would do, as in * `onChange`. * - `event.preventDefault()` stops the change: nothing is written, nothing * re-renders, `onChange` does not fire. The popup's open state does not * change; a click has already moved the active option to the clicked row. * - A change that would change nothing never fires it: the clear button on * an empty selection, the choose-all row with nothing to act on. * - Runs **after** the protected `onChosenChanging` hook. Both run, either may * cancel, and `event.defaultPrevented` shows the hook's decision. * - A setter called from inside the handler wins, `setItems` included: the * pending change is dropped. That change reports `meta.source` `'user'`, * as the first change of the interaction. * - For a confirmation dialog: call `event.preventDefault()`, open the * dialog, and call a setter after the user agreed. That change reports * `meta.source` `'api'`. * - An error thrown by a handler propagates. The change does not happen. * - `null` (default) = nothing is called; no user change is ever stopped * by it. * @group Events */ onBeforeChange: ((nextChosenItems: readonly T[], previousChosenItems: readonly T[], event: LLSelectBeforeChangeEvent<T>) => void) | null; /** * Render the trigger's content ELEMENT without subclassing - the setting * equivalent of overriding `renderTriggerContent`. Receives the chosen items * + items (same convention as `createPopupListItemContentElFn`): * - Called on **every** trigger content render (`renderTriggerContent`: every full trigger render, plus every `setItems`); nothing is kept for a later call. * - `HTMLElement` - inserted into the trigger as-is; you own it. Use this for * real markup such as icons beside the text. * - fn returns `null` - use the default for this render (count text / tags). * - setting is `null` (default) - always use that default rendering. * - The element is for the screen only: the content slot carries * `aria-hidden="true"`, and a screen reader reads the text of * `triggerContextToScreenReaderTextFn` instead. Put no control in it. * The DEFAULT `renderTriggerContent` checks it first; a subclass override * replaces that default entirely and may ignore the setting - override * wins, per DESIGN.md "Customization model". * @group Trigger */ createTriggerContentElFn: ((ctx: LLSelectMultipleTriggerContext<T>) => HTMLElement | null) | null; /** * The text a screen reader reads as the trigger's value, never shown. * - Called on **every** trigger content render (`renderTriggerContent`: * every full trigger render, plus every `setItems`), once, after that * render, through `computeTriggerScreenReaderText`; nothing is kept for a * later call. * - Why a separate text: the trigger has `role="combobox"`, and WAI-ARIA * 1.2 gives a combobox that is not a text field the value of its * descendant content. The library hides the visible content from * assistive technology with `aria-hidden="true"` and puts this text in a * visually hidden span inside the trigger, so the screen reader reads * this text and nothing that only decorates the screen. * - Return a string, and the library writes it as plain text. * - `null`, returned or as the setting (the default), and a blank string * mean the default, which reads out what the screen shows: * - in `'count'` mode, `uiTranslationPack.triggerScreenReaderCountText`, * English "3 of 74 selected"; * - in `'tags'` mode, `uiTranslationPack.triggerScreenReaderItemsText` * with the chosen items' `itemToString` texts, English "TypeScript, Rust"; * - the placeholder while nothing is chosen. * - `createTriggerContentElFn` never changes this text: the library never * reads custom content, and the default of the current mode applies. * @group Trigger */ triggerContextToScreenReaderTextFn: ((ctx: LLSelectMultipleTriggerContext<T>) => string | null) | null; /** * Trigger display mode. * - `'count'` (default): a summary like "3 / 10 selected". * - `'tags'`: one removable chip per chosen item; its x button removes it. * `createTriggerContentElFn` overrides both (full control wins). * @group Trigger */ triggerDisplay: LLSelectTriggerDisplay; /** * Item -> the visible content ELEMENT of its tag chip in `'tags'` mode, * without subclassing. Mirrors `createPopupListItemContentElFn` (the chip is to the * trigger what the option content is to the row): * - Called once per chosen item on **every** trigger content render (`renderTriggerContent`: every full trigger render, plus every `setItems`) while `triggerDisplay` is `'tags'`, unless `createTriggerContentElFn` returns an element; nothing is kept for a later call. * - Return an `HTMLElement` and the library inserts it as the chip's content; * the library still owns the chip container + the remove (x) button + aria. * - `null` (setting default, or returned for an item) = plain text from * `itemToString`. * - The library sets `aria-hidden="true"` on the element you return. The * chip sits in the trigger buttons strip, a toolbar in which only the * buttons speak. The item reaches assistive technology through the * trigger's screen-reader text and through the remove button's name, from * `itemToTagRemoveButtonAriaLabel` (default `Remove <itemToString>`). * - So put no control in the element, and no text meant only for screen * readers. See `docs/llm/A11Y.md` "Tags". * - The library sets the item's `lang` from `itemToLangFn` on the element * you return, overwriting yours, when that function returns a code; it * never removes the attribute. * @group Trigger */ createTagContentElFn: ((item: T) => HTMLElement | null) | null; /** * Icon ELEMENT of each tag's remove (x) button in `'tags'` mode, mirroring * `createTriggerClearButtonContentElFn` (the clear button's icon hook). The library always owns the * button, its click (removes the item + `stopPropagation`), its `tabindex` * (one button of the trigger buttons strip is the Tab stop), and the * `aria-label` accessible name (from `itemToTagRemoveButtonAriaLabel`); * this only fills the decorative icon. * - Called once per chosen item on **every** trigger content render (`renderTriggerContent`: every full trigger render, plus every `setItems`) while `triggerDisplay` is `'tags'`, unless `createTriggerContentElFn` returns an element; nothing is kept for a later call. * - Return an `HTMLElement` / `SVGElement`: appended inside the button as its icon. * - `null` (setting default, or returned for an item): no icon - the theme * draws the x via its CSS glyph (`.llselect-tag-remove-button:empty::before`). * @group Trigger */ createTagRemoveButtonContentElFn: ((item: T) => HTMLElement | SVGElement | null) | null; /** * Hide the rows of chosen items from the popup list. * - Default `false`: chosen rows stay listed and show their state. * - While `true`, choosing an item removes its row at once and unchoosing * puts it back. Tags, the trigger and `getChosenItems` are unaffected. * - When every item is chosen, the popup shows the no-results element. * - With `chooseAllRow`, the visible subset is always fully unchosen, so * the row acts as "choose everything still listed", its tri-state never * reaches all-chosen, and it disappears with the last actionable row. * - Internals: a `getVisibleItems` subtraction. The default `compareFn` * uses a Set lookup; a custom `compareFn` costs O(visible x chosen). * Either cost is paid once per change of the list or the chosen set - * the result is cached between changes. `toggleItem` swaps its O(1) row * replace for a full rebuild. * @group Popup */ hideChosenRows: boolean; /** * Order of the chosen items. Tags, `getChosenItems`, `onChange` and a * framework model all see this order. * - `'as-chosen'` (default): the order the items were chosen in. * `setChosenItems` keeps the caller's order. * - `'as-listed'`: the order of the item list. `setChosenItems([b, a])` is * stored as `[a, b]`. When `setItems` reorders the list, the chosen * items follow and `onChange` fires. A chosen item the list does not * hold goes last, in chosen order, until the next `setItems` drops it. * - Cost of `'as-listed'`, per add or replace: a sort of the chosen items, * O(chosen log chosen). * - The list positions come from a table built once per item list, O(list) * after each `setItems`. * - A custom `compareFn` skips the table: each add or replace is * O(chosen x list + chosen log chosen). * - A `setItems` that drops or reorders chosen items rebuilds an open popup * a second time (see `setItems`). * @group Selection */ chosenItemsOrder: LLSelectChosenItemsOrder; /** * Whether the popup shows a choose-all row (the industry's "select all") * as the first option of the listbox. * - Default `false`. * - Activating the row (Enter, click, or Space while the filter is off) * commits what `toggleAllVisible` computes, after the before-change * gate: it toggles the items `getVisibleEnabledItems()` * returns; that method's docstring defines exactly which items those * are. The public `chooseAll` / `unchooseAll` / `toggleAll` keep their * whole-list semantics. * - The row is tri-state (none / some / all chosen), carried by the * counting text's numbers and the `data-chosen-state` CSS hook. * - Its accessible name comes from `uiTranslationPack.chooseAllRowText`. * - See `docs/llm/A11Y.md` "Choose-all". * @group Choose-all */ chooseAllRow: boolean; /** * The choose-all row's visible content ELEMENT, without subclassing - e.g. * a tri-state SVG checkbox (`createOutlinedCheckboxSvgEl`) + the counting text. Mirrors * `createPopupListItemContentElFn`. Only used with `chooseAllRow: true`. * - Called **every** time the choose-all row is built, which needs the popup open and an enabled visible item; nothing is kept for a later call: * - on each full list render (`renderPopupList`); * - on each `toggleItem` with `hideChosenRows` off, which rebuilds the row in place (with it on, `toggleItem` runs a full list render). * - Receives the tri-state and the counts of the visible enabled subset. * - Return an `HTMLElement`: inserted as the row's content; the accessible * name stays pinned to `uiTranslationPack.chooseAllRowText` via `aria-label`, so * icon-only content is still announced with the counts. * - `null` (setting default, or returned): the default content - just the * plain counting text; its numbers carry the tri-state. The library * ships no default indicator (consistent with items and the arrow); * passing this setting is how one (e.g. `createOutlinedCheckboxSvgEl`) * gets added. See DESIGN.md "Choose-all default: plain counting text". * @group Choose-all */ createChooseAllRowContentElFn: ((chosenState: LLSelectChosenState, chosenCount: number, totalCount: number) => HTMLElement | null) | null; } /** * Constructor-time settings input for {@link LLSelectMultiple}. * Every field is optional; missing fields use defaults. * @group Settings * @category Multiple */ export type LLSelectMultipleSettingsInput<T, GroupKey = string> = LLSelectSettingsInputOf<LLSelectMultipleSettings<T, GroupKey>>; /** * Multi-selection select component. Clicking an item toggles its membership in * the chosen-items set and keeps the popup open. Each item DOM gets * `aria-selected="true|false"`; the popup list gets * `aria-multiselectable="true"`. * * Default trigger display is a count text ("3 / 10 selected" / "All N * selected" / placeholder when empty). Set `triggerDisplay: 'tags'` for chips, * or pass `createTriggerContentElFn` (or subclass `renderTriggerContent`) for * custom markup. * * @typeParam T - item type. * @typeParam GroupKey - group key type of `itemToGroupKeyFn`; see * {@link LLSelectBase}. * @typeParam S - resolved settings type, for subclasses extending the * settings bag; see {@link LLSelectBase}. * @group Select component classes */ export declare class LLSelectMultiple<T = unknown, GroupKey = string, S extends LLSelectMultipleSettings<T, GroupKey> = LLSelectMultipleSettings<T, GroupKey>> extends LLSelectBase<T, GroupKey, S> { /** * Currently chosen items, in `chosenItemsOrder` order (chosen order by default). * @group State (protected) */ protected chosenItems: readonly T[]; /** The item whose text the default screen-reader text is, for its `lang`; set by `computeTriggerScreenReaderText`, read once by `computeTriggerScreenReaderTextLang`. */ private screenReaderTextSource; /** * Build the control inside `targetEl`. * - Settings are resolved once here; missing fields get defaults. * - They are frozen afterwards, except `placeholder` and `uiTranslationPack`, * which have runtime setters; the rule is at {@link LLSelectBaseSettings}. * - This plain form infers `T` from a typed callback in `settings` whose * signature contains `T` (`itemToStringFn: (u: User) => ...`). With no * such callback, pass `T` explicitly: `new LLSelectMultiple<string>(...)`. * @group Lifecycle */ constructor(targetEl: HTMLElement, settings?: LLSelectMultipleSettingsInput<T, GroupKey>); /** * Subclass form. `subclassSettings` is the typed pass-through for subclasses * that extend the settings bag further; see `LLSelectBase`'s `S` param. * @group Lifecycle */ constructor(targetEl: HTMLElement, settings?: LLSelectSettingsInputOf<S>, subclassSettings?: Omit<S, keyof LLSelectMultipleSettings<T, GroupKey>>); /** * Return the currently chosen items, in `chosenItemsOrder` order (chosen order by default). * @group Selection */ getChosenItems(): readonly T[]; /** * Replace the entire chosen-items list. * - The input is copied, and duplicates (per `compareFn`) collapse to * their first occurrence: the chosen items are a set. * - Fires `onChange` only when the new list differs from the current one. * The comparison is order-sensitive: chosen order is visible state * (tags render in it). * - When `chosenItemsOrder` is `'as-listed'`, the input is first put in list * order, so a write of the same set in another order is no change for * items the list holds. * - When `chosenItemsOrder` is `'as-listed'`, unlisted items go last, * keeping their order relative to each other. * - It ignores disabled state: it can add and drop disabled items, unlike * the `choose*` bulk ops. Assigning to a native `<select>` behaves the * same. * @group Selection */ setChosenItems(chosenItems: readonly T[]): void; /** * Whether the given item is currently chosen (via `compareFn`). * @group Selection */ isChosen(item: T): boolean; private chosenSetCache; /** Memoized Set of `chosenItems` for the default-compareFn `isChosen` fast path. */ private chosenSet; /** * Toggle the membership of `item` in the chosen-items set. Fires `onChange`. * - If the item is not chosen, it is added at the end. * - When `chosenItemsOrder` is `'as-listed'`, it is added at its list * position instead. * - If the item is chosen, it is removed. * - While `hideChosenRows` is on, the popup list is rebuilt so the row * leaves or re-enters it. * @group Selection */ toggleItem(item: T): void; /** * Choose every enabled item. * - It chooses only enabled items from the current item list, like every * `choose*` bulk op. Bulk ops mirror clicking, and clicking cannot reach * disabled items. * - Already-chosen disabled items in the current item list are preserved. * To change disabled items too, use `setChosenItems`. * - `setChosenItems()` and `toggleItem()` accept items outside the current * item list. If a chosen item is outside that list, this method drops it * when it rebuilds the selection, disabled or not. * - Fires `onChange` only when the chosen items actually change. * @group Selection */ chooseAll(): void; /** * Unchoose every enabled item. * - It filters the chosen set: every enabled chosen item leaves the * selection, even if the item is outside the current item list. * - Every disabled chosen item stays chosen, even if the item is outside * the current item list. * - Clicking a disabled item does not change its selection state, and this * method follows that rule. * - The paths that DO drop them: * - the clear button, when `clearable` is on and the control is enabled; * - `toggleItem()` with the item; * - `setChosenItems()` with a selection that excludes the item; * - `setItems()` with a list that no longer contains the item; * - `chooseAll()`, if the item is outside the current item list: it * rebuilds the selection from that list, which drops the item * (`setChosenItems()` and `toggleItem()` can select items outside * the list); * - `toggleAll()`, if the item is outside the current item list, in the * two cases where it calls `chooseAll()`: the list has no enabled item, * or an enabled item in the list is unchosen. * - Fires `onChange` only when the chosen items actually change. * @group Selection */ unchooseAll(): void; /** * Toggle between "all enabled chosen" and "all enabled unchosen". * - If the current item list holds at least one enabled item and every * enabled item is chosen: * - It calls `unchooseAll()`. * - Every enabled chosen item leaves the selection, even if the item is * outside the current item list. * - Every disabled chosen item stays chosen, even if the item is outside * the current item list. * - Otherwise: * - It calls `chooseAll()`. * - Every enabled item in the current item list becomes chosen. * - Disabled chosen items in the current item list stay chosen. * - Chosen items outside the current item list leave the selection, * disabled or not. * - Disabled items in the current item list keep their selection state, * like with every `choose*` bulk op. * - This is NOT the in-popup choose-all row's action. The row acts on the * visible enabled subset only: see {@link toggleAllVisible}. * @group Selection */ toggleAll(): void; /** * Toggle the visible enabled items between all-chosen and all-unchosen. * - This is the choose-all row's action (the `chooseAllRow` setting) as a * public method. The row computes the same next value and commits it * through the before-change gate, so an override here does not change * the row. * - Acts on exactly the items that satisfy all of the following: * - Visible: the item is in `getVisibleItems()`. It matches the active * filter query, and with `hideChosenRows` it is not chosen. With no * query and without `hideChosenRows`, every item is visible. * - Enabled: not disabled via `itemDisabledFn`, and not in a disabled * group. * - If all of them are already chosen, it unchooses exactly those. * - Otherwise, it chooses the ones still missing. * - When `hideChosenRows` is on, a chosen item is not visible, so this * method only chooses. * - If this method does not act on a chosen item, that item stays chosen. * This covers: * - items hidden by the active filter query; * - items hidden by `hideChosenRows`; * - disabled items; * - chosen items outside the current item list (`setChosenItems()` and * `toggleItem()` accept such items). * - When there is no filter query and `hideChosenRows` is off, this method * acts on every enabled item of the current item list. * - `toggleAll` can drop chosen items outside the current item list: * - If the current item list has no enabled item, or an enabled item in * that list is unchosen, `toggleAll` calls `chooseAll()`. That call * drops every chosen item outside the list, disabled or not. * - Otherwise `toggleAll` calls `unchooseAll()`. That call clears every * enabled chosen item outside the list and keeps the disabled ones. * - Fires `onChange` only when the chosen items actually change. * - The acted-on set is computed by the overridable method `getVisibleEnabledItems`, * shared with the choose-all row. * @group Selection */ toggleAllVisible(): void; /** * What the choose-all row would commit: the normalized next chosen array, * or `null` when nothing is actionable. Shared by `toggleAllVisible` and * the before-change gate, so the hook sees exactly what the setter commits. */ private nextAfterToggleAllVisible; /** * Dedupe and order a raw chosen array: set semantics, as compareFn's * contract promises. The choose* bulk ops filter through isChosen and never * produce duplicates; setChosenItems is the one door raw arrays (framework * model write-back included) come in through, so the dedup lives here. */ private normalizeChosen; /** * What a toggle of `item` would do: the next chosen array, whether the item * leaves, and the entry that changes. Shared by `toggleItem` and the * before-change gate, so the hook sees exactly what the setter commits. * - The removed entry is the STORED one: with a key-based compareFn the * caller's `item` may be a different, equal object, and meta.item must * name what left the selection. */ private nextAfterToggle; /** * Return the items a "select all" acts on: the visible, enabled ones. * - Visible: the item is in `getVisibleItems()`. It matches the active * filter query, and with `hideChosenRows` it is not chosen. With no * query and without `hideChosenRows`, every item is visible. * - Enabled: not disabled via `itemDisabledFn`, and not in a disabled group. * - The choose-all row (its counts, its tri-state, its click) and * `toggleAllVisible()` both read this method. * - Use it to build your own select-all as an action row, for example in * the trailing rows: count the chosen items with `isChosen`, write the * text with `getUiTranslationPack().chooseAllRowText(chosen, total)`, and * call `toggleAllVisible()` from `onActivate`. * - Such a row is a command, not the built-in row: * - its `aria-selected` is always `false`; * - it has no `data-chosen-state`, so the themes give it no tri-state look; * - it is never the active option when the popup opens; * - it stays rendered when this list is empty. * - For a row that follows the selection, looks tri-state, can be the * initial active option and hides itself, use `chooseAllRow`. * - Override it to change the subset. The tree-select demo narrows it to * leaf nodes; the choose-all row and `toggleAllVisible()` follow the * override. * @group Selection */ getVisibleEnabledItems(): readonly T[]; /** * hideChosenRows subtraction cache. Every layer above (items, gather, * filter) and the chosen set REPLACE their arrays on change, never mutate * in place - so two reference checks are a complete validity test and no * invalidation wiring is needed. */ private visibleItemsCache; /** * Return the items the popup list renders, in display order. * * ```text * base visible items (LLSelectBase.getVisibleItems: gather + filter) * | minus chosen (only while hideChosenRows is on; result cached) * v * visible items (this method's return value) * ``` * * - Identical to the base behavior, minus the chosen items while * `hideChosenRows` is on. * - While `hideChosenRows` is on and something is chosen, it returns a * cached fresh array, not the live internal one. * - The subtraction recomputes only when the base list or the chosen set * changed. Calls in between return the same cached array. * @group Items */ getVisibleItems(): readonly T[]; /** * Orchestrator: composes `syncEmptyStateToDom` + `commitTriggerContentToDom` * + `commitTagsElToDom` to (re)build the trigger from state; touches no DOM * directly. Default text is a count text; override (or pass the * `createTriggerContentElFn` setting) to display custom markup. * * - If 0 items are chosen, the text is `placeholder`. * - If n > 0, the text is `uiTranslationPack.triggerContentCountText(n, total)` * (English default: `"n / total selected"`, or `"All n selected"` when * all are chosen). * - In `'tags'` mode the chips from `createTagsEl` go into the trigger * buttons strip, and the content slot stays empty while they show. * - What a screen reader reads comes from `computeTriggerScreenReaderText`, * which the library calls after this render. * @group Subclassing: rendering */ protected renderTriggerContent(): void; /** * The screen-reader text: the value assistive technology reads for the * trigger, never shown. See the base method for why it exists. * - The library calls it after every trigger content render. * - Default: the text of `triggerContextToScreenReaderTextFn`; when that * gives `null` or a blank string, the text of the current mode, the same * with custom trigger content: * - in `'count'` mode, `uiTranslationPack.triggerScreenReaderCountText`; * - in `'tags'` mode, `uiTranslationPack.triggerScreenReaderItemsText` * with the chosen items' `itemToString` texts, in the chosen order; * - the placeholder while nothing is chosen. * @group Subclassing: semantics */ protected computeTriggerScreenReaderText(): string; /** * The chosen item's `lang` while the screen-reader text is exactly that * item's text: one chip; joined texts and the count text carry none. * @internal */ protected computeTriggerScreenReaderTextLang(text: string): string | null; /** * Whether the trigger shows chips: `triggerDisplay: 'tags'`. * @internal */ protected isTriggerDisplayTags(): boolean; /** * Build the tag-list element for `'tags'` mode: one chip per chosen item. * - The library puts it into the trigger buttons strip, before the clear * button. * - The arrow keys of the strip move between its `button` elements. * - Override for full control of the chip list (the trigger-level * equivalent of overriding `createPopupListItemEl`). * @group Subclassing: rendering */ protected createTagsEl(): HTMLElement; /** * Build one removable tag chip: its content (from `createTagContentEl`, else * plain `itemToString` in a span of its own) plus its remove (x) button (from * `createTagRemoveButtonEl`). The content element carries the item's `lang` * from `itemToLang` when it returns one; the button never does. * - The content element gets `aria-hidden="true"`. The chip sits in the * trigger buttons strip, a toolbar, where only the buttons speak: the * item text already reaches assistive technology through the trigger's * value and through the remove button's name. * - A chip whose item is effectively disabled gets `aria-disabled="true"` + * `tagDisabledClass`, and its x turns inert - mirroring a disabled option * row. * - Override for full control of the chip container; override the two * sub-parts for content-only / remove-button-only changes. * @group Subclassing: rendering */ protected createTagEl(item: T): HTMLElement; /** * Build one chip's remove (x) button. The library owns the button + its click * (`stopPropagation` so it never toggles the popup, then the gated toggle, * which `onChosenChanging` and `onBeforeChange` may stop, else `toggleItem`; a no-op * while the whole control OR the item itself is disabled) + * `aria-label` (from `itemToTagRemoveButtonAriaLabel`). An effectively-disabled * item's button also gets `aria-disabled="true"`. * - The trigger buttons strip owns its `tabindex`: one button of the strip * is the Tab stop. * - An override returns a `button` element: the strip's Tab stop and arrow * keys reach `button` elements only. * - After a removal by keyboard, focus moves to the next chip's button, else * to the previous one, else to the trigger when no chip is left * (`commitTagsElToDom`). * - `createTagRemoveButtonContentElFn` optionally fills the icon, else the * theme's CSS glyph. * - Mirrors the clear button's `createTriggerClearButtonEl`. Override for * full control of the button element. * @group Subclassing: rendering */ protected createTagRemoveButtonEl(item: T): HTMLElement; /** * One chip's remove-button visible content (its x icon). Mirrors * `createTriggerClearButtonContentEl`. * - Default reads `createTagRemoveButtonContentElFn`; `null` (setting unset, * or returned) = no icon - the theme's CSS glyph draws the x. * - Override only when extending; for one-off icons pass the setting. * @group Subclassing: rendering */ protected createTagRemoveButtonContentEl(item: T): HTMLElement | SVGElement | null; /** * Per-chip visible content in `'tags'` mode. Mirrors `createPopupListItemContentEl`. * Default reads `createTagContentElFn`, else `null` so `createTagEl` falls * back to plain text from `itemToString`. * @group Subclassing: rendering */ protected createTagContentEl(item: T): HTMLElement | null; /** * Item -> its remove button's accessible name in `'tags'` mode. * - Default: `uiTranslationPack.tagRemoveButtonAriaLabel(itemToString(item))`. * - Override only when extending (e.g. a name from another item field); * per-locale text goes through the `uiTranslationPack` setting. * @group Subclassing: semantics */ protected itemToTagRemoveButtonAriaLabel(item: T): string; /** * No selection iff the chosen set is empty. Drives the trigger wrapper's `data-empty`. * @group Subclassing: semantics */ protected isEmpty(): boolean; /** * Toggle the item **after** Enter on its row while it is the active row, Space * on it while the filter is inactive, or a click on it, once `onChosenChanging` * and `onBeforeChange` allowed it. Multi mode keeps the popup open either way. * * > No **before** counterpart: there is no `onPopupListItemActivating`. * @group Subclassing: reactions */ protected onPopupListItemActivated(item: T): void; /** The gated toggle shared by the row activation and the tag remove button. */ private requestAndToggle; /** * Clear button empties the chosen-items set to `[]`, after asking * `onChosenChanging` and `onBeforeChange`. * @group Subclassing: semantics */ protected clearSelection(): void; /** * Subclass hook: called **before** a user interaction changes the chosen items, * with the way to stop it. Default no-op. * * > Pairs with `onChosenChanged`, which runs **after** the change was written. * * - Runs **before** the `onBeforeChange` setting. Both run, either may call * `event.preventDefault()`. * - The parameters are the setting's: the list about to be set, the * current one, the event. * @group Subclassing: reactions */ protected onChosenChanging(_nextChosenItems: readonly T[], _previousChosenItems: readonly T[], _event: LLSelectBeforeChangeEvent<T>): void; /** * The gate every user path to a change runs through: skips a no-op, asks the * hook and the setting, and says whether the setter may run. */ private requestUserChange; /** * Build the choose-all row (`chooseAllRow` setting), the listbox's leading * `role="option"` row. * - The library calls it on every full list render (`renderPopupList`), and * when a toggle rebuilds the row in place (`replaceChooseAllRowElInDom`). * You never call it. * - To change only what the row shows, do not override this: pass the * `createChooseAllRowContentElFn` setting. * - To change the element itself, override it, call * `super.createPopupListChooseAllRowEl()`, and edit the returned element. * Keep the `id`, the `role` and `aria-selected`; put no focusable control * inside. * - `super` returns `null` in two cases; return `null` then too: * - the `chooseAllRow` setting is off; * - no visible item is enabled, so nothing is actionable. * - `data-chosen-state` is `none`, `some` or `all`: a CSS styling hook. * - `aria-selected` is `"true"` when every visible enabled item is chosen, * and `"false"` otherwise. * - The accessible name and the visible text come from * `uiTranslationPack.chooseAllRowText(chosenCount, totalCount)`, counted * over the visible enabled subset. * - `null` means no row. * - After this returns, the library adds `aria-posinset` and * `aria-setsize`: the row is a non-item row, so its list always gets them. * @group Subclassing: rendering */ protected createPopupListChooseAllRowEl(): HTMLElement | null; /** * The choose-all row's visible content (rich tri-state). Mirrors * `createPopupListItemContentEl`. * - Default reads `createChooseAllRowContentElFn`; `null` (setting unset, * or returned) = the default content: plain text from * `uiTranslationPack.chooseAllRowText`. * - Override only when extending; for one-off content pass the setting. * @group Subclassing: rendering */ protected createChooseAllRowContentEl(chosenState: LLSelectChosenState, chosenCount: number, totalCount: number): HTMLElement | null; /** * Runs **after** Enter on the active choose-all row, Space on it while the * filter is inactive, or a click on it, as the library's response to that * input. * * > No **before** counterpart: there is no `onChooseAllRowActivating`. * * - Computes what {@link toggleAllVisible} would commit. * - Asks `onChosenChanging` and `onBeforeChange` with that value. * - Then commits exactly that value, even if a handler changed which items * are enabled. * @group Subclassing: reactions */ protected onChooseAllRowActivated(): void; /** * Mark each item with `aria-selected` reflecting its chosen state. * @group Subclassing: rendering */ protected createPopupListItemEl(item: T, index: number): HTMLElement; /** * Re-match the chosen entries against the new list **after** `setItems` installs it. * * > No **before** counterpart: there is no `onItemsChanging`. * * - Entries the list no longer holds (by `compareFn`) are dropped and * `onChange` fires for the drop. * - When the list holds a compareFn-equal but DIFFERENT object (`track by` * style reload: same key, fresh fields), the stored reference is swapped * to the list's object. A reference swap is not a logical change, so it * does not fire `onChange`. * - The trigger content re-renders after every `setItems`, swap or not. * - Why: the count text shows the list total, and a custom * `createTriggerContentElFn` receives `items`. * - The arrow re-renders only when a chosen entry is dropped, because that * runs the whole trigger. * - `triggerDisplay: 'tags'` is opt-in; `'count'` is the default. * - When `triggerDisplay` is `'tags'`, that render is one chip per chosen * item per `setItems`, unless `createTriggerContentElFn` replaces the * content. * - That cost is acceptable: `setItems` is a bulk call. * @group Subclassing: reactions */ protected onItemsChanged(): void; /** * Decide which row is active when the popup opens. * - The library calls it inside `open()`, once per open, after the rows * are built. You never call it. * - To pick another row, override it and set the row with * `setFocusedIndex` or `focusChooseAllRow`. * - `setFocusedIndex` takes an index into `getVisibleItems()`, which * counts item rows only; the choose-all row and the action rows have no * index. * - To fall back to this method's choice, call `super.focusInitial()`, but * only when the override set no row. * - The active row is the `role="option"` row that `aria-activedescendant` * names on the `role="combobox"` element: the trigger, or the filter * input while the filter is active. * - "Focus" in the names `focusInitial`, `setFocusedIndex` and * `focusChooseAllRow` means the active row, not DOM focus. * - DOM focus never moves to the active row. While the filter is active, * the open moves DOM focus to the filter input. * - `open()` clears the active row before the call, so the popup opens * with no active row unless this method sets one. * - Visible items are the items in `getVisibleItems()`, the items that * have a row in the list. * - While `hideChosenRows` is on, a chosen item is not visible. * - Makes the row of the first entry of `getChosenItems()` active, if that * item is visible and enabled. * - `getChosenItems()` follows `chosenItemsOrder`, not the order of the * rows, so its first entry need not be the topmost chosen row. * - Otherwise makes the choose-all row active, when it is rendered. * - The choose-all row is the first `role="option"` row of the listbox, * so making it active at open lets a keyboard user find it without * pressing an arrow key. * - Otherwise makes the first enabled visible item the active row. * - This order is the one `docs/llm/A11Y.md` rules, and an action row is * never the active row at open. * - Each step replaces any row set before this method runs. * - Does nothing when no visible item is enabled. * - The choose-all row is rendered only while a visible item is enabled. * @group Subclassing: focus */ protected focusInitial(): void; /** Position of each item in the current list; built once per item list (default `compareFn` only). */ private itemPositionCache; private itemPositions; /** * Apply `chosenItemsOrder`. `'as-chosen'` returns the array as is; * `'as-listed'` sorts by position in the item list, unlisted entries last * in their given order. */ private orderChosen; private arraysEqual; private fireChange; } //# sourceMappingURL=multiple.d.ts.map