import type { CSSResultGroup } from 'lit'; import DSAErrorText from '../error-text/error-text'; import DSAIcon from '../icon/icon'; import DSAOption from '../option/option'; import DSAPopup from '../popup/popup'; import DSASpinner from '../spinner/spinner'; import DSATag from '../tag/tag'; import { FormControlLayout } from '../../internal/components/form-control/form-control-layout'; import type { ShoelaceFormControl } from '../../internal/shoelace-element'; /** * @summary Comboboxes allow you to type a value directly or select a value from a menu of predefined options. Values are filtered by checking the presence of the search term. * @documentation https://dsa.service-public-autonomie.fr/latest/librairie-webcomponents/liste-deroulante/combobox-combobox/web-vIidOR7h * * @dependency dsa-icon * @dependency dsa-popup * @dependency dsa-tag * @dependency dsa-error-text * @dependency dsa-spinner * @dependency dsa-option * * @slot - The listbox options. Must be `` elements. Alternatively, you can use the `items` property. * @slot label - The input's label. Alternatively, you can use the `label` attribute. * @slot prefix - Used to prepend a presentational icon or similar element to the combobox. * @slot help-text - Text that describes how to use the input. Alternatively, you can use the `help-text` attribute. * @slot tooltip - The tooltip slot allows additional information to be passed along the label * @event dsa-after-hide - Emitted after the combobox's menu closes and all animations are complete. * @event dsa-after-show - Emitted after the combobox's menu opens and all animations are complete. * @event dsa-blur - Emitted when the control loses focus. * @event dsa-change - Emitted when the control's value changes. * @event dsa-clear - Emitted when the control's value is cleared. * @event dsa-focus - Emitted when the control gains focus. * @event dsa-hide - Emitted when the combobox's menu closes. * @event dsa-input - Emitted when the control receives input. Debounced according to `debounce-timeout` value. * @event dsa-invalid - Emitted when the form control has been checked for validity and its constraints aren't satisfied. * @event dsa-show - Emitted when the combobox's menu opens. */ export default class DSACombobox extends FormControlLayout implements ShoelaceFormControl { static styles: CSSResultGroup; static dependencies: { 'dsa-icon': typeof DSAIcon; 'dsa-popup': typeof DSAPopup; 'dsa-tag': typeof DSATag; 'dsa-error-text': typeof DSAErrorText; 'dsa-spinner': typeof DSASpinner; 'dsa-option': typeof DSAOption; }; private readonly formControlController; private readonly localize; popup: DSAPopup; combobox: HTMLSlotElement; displayInput: HTMLInputElement; valueInput: HTMLInputElement; listbox: HTMLSlotElement; seeMoreOption: DSAOption | null; private hasVisualFocus; displayLabel: string; currentOption: DSAOption | undefined; selectedOptions: DSAOption[]; allOptions: DSAOption[]; filteredOptions: DSAOption[]; displayedOptionsCount: number; private debounceTimerId; /** * Indicates whether or not the combobox is open. You can toggle this attribute to show and hide the menu, or you can * use the `show()` and `hide()` methods and this attribute will reflect the combobox's open state. */ open: boolean; /** * The current value of the combobox, representing a list of the selected options (or single option if “multiple” is * disabled). Selected options are designated by their value, and separated by a space. It can be used as a way to * define which options are selected by default, and will be sent as name/value pairs with form data. */ value: string | string[]; /** The default value of the form control. Primarily used for resetting the form control. */ defaultValue: string; /** * Enable this option to prevent the listbox from being clipped when the component is placed inside a container with * `overflow: auto|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all, scenarios. */ hoist: boolean; /** * The preferred placement of the combobox's menu. Note that the actual placement may vary as needed to keep the listbox * inside of the viewport. */ placement: 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-start' | 'bottom-end'; /** Adds a clear button when the select is not empty. */ clearable: boolean; /** When set to true, the Popup's width is no longer equal to its anchor's width */ noSyncWidth: boolean; items: DSAOption[] | undefined; /** Allows more than one option to be selected. */ multiple: boolean; /** * The maximum number of selected options to show when `multiple` is true. After the maximum, "+n" will be shown to * indicate the number of additional items that are selected. Set to 0 to remove the limit. */ maxOptionsVisible: number; /** * The number of options that will be displayed by default in the list. Clicking on the "show more" button will display * this number much of new items in the list */ visibleListLength: undefined; /** * Delay between when a user types into an input. It affects the `dsa-input` event. * @default 300 */ debounceTimeout: number; /** * When using asynchronous option loading, allows to specify the fetching state */ fetchingState: 'idle' | 'loading' | 'error' | 'success'; /** Deactivates the combobox inner filtering logic */ overrideDefaultFiltering: boolean; /** Keeps the current search term after selecting an option when multiple is true. */ keepSearchAfterSelection: boolean; /** Gets the validity state object */ get validity(): ValidityState; /** Gets the validation message */ get validationMessage(): string; connectedCallback(): void; /** Input events */ private handleBlur; private handleFocus; private handleComboboxMouseDown; private handleComboboxKeyDown; private handleClearMouseKeyDown; private handleChange; private handleInput; private handleClearClick; private clearSelection; private filterOptions; private resetDisplayedOptionsCount; private resetSearchAfterSelection; private toggleOptionSelection; private handleOptionClick; private handleDefaultSlotChange; private handleTagRemove; private focusNextTagOrInput; private getAllOptions; private clearSelectedOptions; private setCurrentOption; private setSelectedOptions; private handleClearMouseDown; private syncOnSelection; private handleInvalid; /** Listeners */ private addOpenListeners; private removeOpenListeners; private handleDocumentFocusIn; private handleDocumentMouseDown; private handleDefaultKeyDown; private handleEscapeAndTabKeys; private handleEnterKey; private handleSpaceKey; private handleArrowKeys; private handleNavigationKeys; private handleSeeMoreClick; private getDescriptionIds; handleDisabledChange(): void; handleReadonlyChange(): void; handleItemsChange(): void; handleValueChange(): void; handleOpenChange(): Promise; handleDisplayLabelChange(): void; handleMultipleChange(): void; /** Shows the listbox. */ show(): Promise; /** Hides the listbox. */ hide(): Promise; /** Checks for validity but does not show a validation message. Returns `true` when valid and `false` when invalid. */ checkValidity(): boolean; /** Gets the associated form, if one exists. */ getForm(): HTMLFormElement | null; /** Checks for validity and shows the browser's validation message if the control is invalid. */ reportValidity(): boolean; /** Sets a custom validation message. Pass an empty string to restore validity. */ setCustomValidity(message: string): void; /** Sets focus on the control. */ focus(options?: FocusOptions): void; /** Removes focus from the control. */ blur(): void; renderInput(): import("lit").TemplateResult<1>; } declare global { interface HTMLElementTagNameMap { 'dsa-combobox': DSACombobox; } }