UNPKG

primeng

Version:

PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB

1,444 lines (1,406 loc) 136 kB
import * as i1 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { Injectable, forwardRef, EventEmitter, booleanAttribute, numberAttribute, Output, Input, ViewEncapsulation, Component, inject, signal, computed, effect, HostBinding, ContentChildren, ContentChild, ViewChild, ChangeDetectionStrategy, NgModule } from '@angular/core'; import * as i2 from '@angular/forms'; import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { deepEquals, isNotEmpty, isArray, uuid, equals, focus, findLastIndex, resolveFieldData, isPrintableCharacter, getFirstFocusableElement, getLastFocusableElement, findSingle, unblockBodyScroll, hasClass, isHidden, getFocusableElements } from '@primeuix/utils'; import * as i3 from 'primeng/api'; import { SharedModule, TranslationKeys, Footer, Header, PrimeTemplate } from 'primeng/api'; import { AutoFocus } from 'primeng/autofocus'; import { BaseComponent } from 'primeng/basecomponent'; import { Checkbox } from 'primeng/checkbox'; import { Chip } from 'primeng/chip'; import { DomHandler } from 'primeng/dom'; import { IconField } from 'primeng/iconfield'; import { CheckIcon, SearchIcon, TimesIcon, ChevronDownIcon } from 'primeng/icons'; import { InputIcon } from 'primeng/inputicon'; import { InputText } from 'primeng/inputtext'; import { Overlay } from 'primeng/overlay'; import { Ripple } from 'primeng/ripple'; import { Scroller } from 'primeng/scroller'; import { Tooltip } from 'primeng/tooltip'; import { BaseStyle } from 'primeng/base'; import { ObjectUtils } from 'primeng/utils'; const theme = ({ dt }) => ` .p-multiselect { display: inline-flex; cursor: pointer; position: relative; user-select: none; background: ${dt('multiselect.background')}; border: 1px solid ${dt('multiselect.border.color')}; transition: background ${dt('multiselect.transition.duration')}, color ${dt('multiselect.transition.duration')}, border-color ${dt('multiselect.transition.duration')}, outline-color ${dt('multiselect.transition.duration')}, box-shadow ${dt('multiselect.transition.duration')}; border-radius: ${dt('multiselect.border.radius')}; outline-color: transparent; box-shadow: ${dt('multiselect.shadow')}; } .p-multiselect.ng-invalid.ng-dirty { border-color: ${dt('multiselect.invalid.border.color')}; } .p-multiselect:not(.p-disabled):hover { border-color: ${dt('multiselect.hover.border.color')}; } .p-multiselect:not(.p-disabled).p-focus { border-color: ${dt('multiselect.focus.border.color')}; box-shadow: ${dt('multiselect.focus.ring.shadow')}; outline: ${dt('multiselect.focus.ring.width')} ${dt('multiselect.focus.ring.style')} ${dt('multiselect.focus.ring.color')}; outline-offset: ${dt('multiselect.focus.ring.offset')}; } .p-multiselect.p-variant-filled { background: ${dt('multiselect.filled.background')}; } .p-multiselect.p-variant-filled:not(.p-disabled):hover { background: ${dt('multiselect.filled.hover.background')}; } .p-multiselect.p-variant-filled.p-focus { background: ${dt('multiselect.filled.focus.background')}; } .p-multiselect.p-disabled { opacity: 1; background: ${dt('multiselect.disabled.background')}; } .p-multiselect-dropdown { display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: transparent; color: ${dt('multiselect.dropdown.color')}; width: ${dt('multiselect.dropdown.width')}; border-start-end-radius: ${dt('multiselect.border.radius')}; border-end-end-radius: ${dt('multiselect.border.radius')}; } .p-multiselect-label-container { overflow: hidden; flex: 1 1 auto; cursor: pointer; } .p-multiselect-label { display: flex; align-items-center; gap: calc(${dt('multiselect.padding.y')} / 2); white-space: nowrap; cursor: pointer; overflow: hidden; text-overflow: ellipsis; padding: ${dt('multiselect.padding.y')} ${dt('multiselect.padding.x')}; color: ${dt('multiselect.color')}; } .p-multiselect-label.p-placeholder { color: ${dt('multiselect.placeholder.color')}; } p-multiselect.ng-invalid.ng-dirty .p-multiselect-label.p-placeholder { color: ${dt('multiselect.invalid.placeholder.color')}; } .p-multiselect.p-disabled .p-multiselect-label { color: ${dt('multiselect.disabled.color')}; } .p-multiselect-label-empty { overflow: hidden; visibility: hidden; } .p-multiselect .p-multiselect-overlay { min-width: 100%; } .p-multiselect-overlay { background: ${dt('multiselect.overlay.background')}; color: ${dt('multiselect.overlay.color')}; border: 1px solid ${dt('multiselect.overlay.border.color')}; border-radius: ${dt('multiselect.overlay.border.radius')}; box-shadow: ${dt('multiselect.overlay.shadow')}; } .p-multiselect-header { display: flex; align-items: center; padding: ${dt('multiselect.list.header.padding')}; } .p-multiselect-header .p-checkbox { margin-inline-end: ${dt('multiselect.option.gap')}; } .p-multiselect-filter-container { flex: 1 1 auto; } .p-multiselect-filter { width: 100%; } .p-multiselect-list-container { overflow: auto; } .p-multiselect-list { margin: 0; padding: 0; list-style-type: none; padding: ${dt('multiselect.list.padding')}; display: flex; flex-direction: column; gap: ${dt('multiselect.list.gap')} } .p-multiselect-option { cursor: pointer; font-weight: normal; white-space: nowrap; position: relative; overflow: hidden; display: flex; align-items: center; gap: ${dt('multiselect.option.gap')}; padding: ${dt('multiselect.option.padding')}; border: 0 none; color: ${dt('multiselect.option.color')}; background: transparent; transition: background ${dt('multiselect.transition.duration')}, color ${dt('multiselect.transition.duration')}, border-color ${dt('multiselect.transition.duration')}, box-shadow ${dt('multiselect.transition.duration')}, outline-color ${dt('multiselect.transition.duration')}; border-radius: ${dt('multiselect.option.border.radius')} } .p-multiselect-option:not(.p-multiselect-option-selected):not(.p-disabled).p-focus { background: ${dt('multiselect.option.focus.background')}; color: ${dt('multiselect.option.focus.color')}; } .p-multiselect-option.p-multiselect-option-selected { background: ${dt('multiselect.option.selected.background')}; color: ${dt('multiselect.option.selected.color')}; } .p-multiselect-option.p-multiselect-option-selected.p-focus { background: ${dt('multiselect.option.selected.focus.background')}; color: ${dt('multiselect.option.selected.focus.color')}; } .p-multiselect-option-group { cursor: auto; margin: 0; padding: ${dt('multiselect.option.group.padding')}; background: ${dt('multiselect.option.group.background')}; color: ${dt('multiselect.option.group.color')}; font-weight: ${dt('multiselect.option.group.font.weight')}; } .p-multiselect-empty-message { padding: ${dt('multiselect.empty.message.padding')}; } .p-multiselect-label .p-chip { padding-top: calc(${dt('multiselect.padding.y')} / 2); padding-bottom: calc(${dt('multiselect.padding.y')} / 2); border-radius: ${dt('multiselect.chip.border.radius')}; } .p-multiselect-label:has(.p-chip) { padding: calc(${dt('multiselect.padding.y')} / 2) calc(${dt('multiselect.padding.x')} / 2); } .p-multiselect-fluid { display: flex; } .p-multiselect-sm .p-multiselect-label { font-size: ${dt('multiselect.sm.font.size')}; padding-block: ${dt('multiselect.sm.padding.y')}; padding-inline: ${dt('multiselect.sm.padding.x')}; } .p-multiselect-sm .p-multiselect-dropdown .p-icon { font-size: ${dt('multiselect.sm.font.size')}; width: ${dt('multiselect.sm.font.size')}; height: ${dt('multiselect.sm.font.size')}; } .p-multiselect-lg .p-multiselect-label { font-size: ${dt('multiselect.lg.font.size')}; padding-block: ${dt('multiselect.lg.padding.y')}; padding-inline: ${dt('multiselect.lg.padding.x')}; } .p-multiselect-lg .p-multiselect-dropdown .p-icon { font-size: ${dt('multiselect.lg.font.size')}; width: ${dt('multiselect.lg.font.size')}; height: ${dt('multiselect.lg.font.size')}; } .p-multiselect-clear-icon { cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: transparent; color: ${dt('multiselect.clear.icon.color')}; }`; const inlineStyles = { root: ({ props }) => ({ position: props.appendTo === 'self' ? 'relative' : undefined }) }; const classes = { root: ({ instance }) => ({ 'p-multiselect p-component p-inputwrapper': true, 'p-multiselect-display-chip': instance.display === 'chip', 'p-disabled': instance.disabled, 'p-invalid': instance.invalid, 'p-variant-filled': instance.variant ? instance.variant === 'filled' : instance.config.inputStyle === 'filled', 'p-focus': instance.focused, 'p-inputwrapper-filled': instance.filled, 'p-inputwrapper-focus': instance.focused || instance.overlayVisible, 'p-multiselect-open': instance.overlayVisible, 'p-multiselect-fluid': instance.hasFluid, 'p-multiselect-sm p-inputfield-sm': instance.size === 'small', 'p-multiselect-lg p-inputfield-lg': instance.size === 'large' }), labelContainer: 'p-multiselect-label-container', label: ({ instance }) => ({ 'p-multiselect-label': true, 'p-placeholder': instance.label() === instance.placeholder(), 'p-multiselect-label-empty': !instance.placeholder() && !instance.defaultLabel && (!instance.modelValue() || instance.modelValue().length === 0) }), chipItem: 'p-multiselect-chip-item', pcChip: 'p-multiselect-chip', chipIcon: 'p-multiselect-chip-icon', dropdown: 'p-multiselect-dropdown', loadingIcon: 'p-multiselect-loading-icon', dropdownIcon: 'p-multiselect-dropdown-icon', overlay: 'p-multiselect-overlay p-component', header: 'p-multiselect-header', pcFilterContainer: 'p-multiselect-filter-container', pcFilter: 'p-multiselect-filter', listContainer: 'p-multiselect-list-container', list: 'p-multiselect-list', optionGroup: 'p-multiselect-option-group', option: ({ instance, option, index, getItemOptions }) => ({ 'p-multiselect-option': true, 'p-multiselect-option-selected': instance.isSelected(option) && instance.highlightOnSelect, 'p-focus': instance.focusedOptionIndex === instance.getOptionIndex(index, getItemOptions), 'p-disabled': instance.isOptionDisabled(option) }), emptyMessage: 'p-multiselect-empty-message' }; class MultiSelectStyle extends BaseStyle { name = 'multiselect'; theme = theme; classes = classes; inlineStyles = inlineStyles; static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MultiSelectStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MultiSelectStyle }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MultiSelectStyle, decorators: [{ type: Injectable }] }); /** * * MultiSelect is used to select multiple items from a collection. * * [Live Demo](https://www.primeng.org/multiselect/) * * @module multiselectstyle * */ var MultiSelectClasses; (function (MultiSelectClasses) { /** * Class name of the root element */ MultiSelectClasses["root"] = "p-multiselect"; /** * Class name of the label container element */ MultiSelectClasses["labelContainer"] = "p-multiselect-label-container"; /** * Class name of the label element */ MultiSelectClasses["label"] = "p-multiselect-label"; /** * Class name of the chip item element */ MultiSelectClasses["chipItem"] = "p-multiselect-chip-item"; /** * Class name of the chip element */ MultiSelectClasses["pcChip"] = "p-multiselect-chip"; /** * Class name of the chip icon element */ MultiSelectClasses["chipIcon"] = "p-multiselect-chip-icon"; /** * Class name of the dropdown element */ MultiSelectClasses["dropdown"] = "p-multiselect-dropdown"; /** * Class name of the loading icon element */ MultiSelectClasses["loadingIcon"] = "p-multiselect-loading-icon"; /** * Class name of the dropdown icon element */ MultiSelectClasses["dropdownIcon"] = "p-multiselect-dropdown-icon"; /** * Class name of the overlay element */ MultiSelectClasses["overlay"] = "p-multiselect-overlay"; /** * Class name of the header element */ MultiSelectClasses["header"] = "p-multiselect-header"; /** * Class name of the filter container element */ MultiSelectClasses["pcFilterContainer"] = "p-multiselect-filter-container"; /** * Class name of the filter element */ MultiSelectClasses["pcFilter"] = "p-multiselect-filter"; /** * Class name of the list container element */ MultiSelectClasses["listContainer"] = "p-multiselect-list-container"; /** * Class name of the list element */ MultiSelectClasses["list"] = "p-multiselect-list"; /** * Class name of the option group element */ MultiSelectClasses["optionGroup"] = "p-multiselect-option-group"; /** * Class name of the option element */ MultiSelectClasses["option"] = "p-multiselect-option"; /** * Class name of the empty message element */ MultiSelectClasses["emptyMessage"] = "p-multiselect-empty-message"; })(MultiSelectClasses || (MultiSelectClasses = {})); const MULTISELECT_VALUE_ACCESSOR = { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => MultiSelect), multi: true }; class MultiSelectItem extends BaseComponent { id; option; selected; label; disabled; itemSize; focused; ariaPosInset; ariaSetSize; variant; template; checkIconTemplate; itemCheckboxIconTemplate; onClick = new EventEmitter(); onMouseEnter = new EventEmitter(); onOptionClick(event) { this.onClick.emit({ originalEvent: event, option: this.option, selected: this.selected }); event.stopPropagation(); event.preventDefault(); } onOptionMouseEnter(event) { this.onMouseEnter.emit({ originalEvent: event, option: this.option, selected: this.selected }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MultiSelectItem, deps: null, target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.2", type: MultiSelectItem, isStandalone: true, selector: "p-multiSelectItem, p-multiselect-item", inputs: { id: "id", option: "option", selected: ["selected", "selected", booleanAttribute], label: "label", disabled: ["disabled", "disabled", booleanAttribute], itemSize: ["itemSize", "itemSize", numberAttribute], focused: ["focused", "focused", booleanAttribute], ariaPosInset: "ariaPosInset", ariaSetSize: "ariaSetSize", variant: "variant", template: "template", checkIconTemplate: "checkIconTemplate", itemCheckboxIconTemplate: "itemCheckboxIconTemplate" }, outputs: { onClick: "onClick", onMouseEnter: "onMouseEnter" }, usesInheritance: true, ngImport: i0, template: ` <li pRipple role="option" [ngStyle]="{ height: itemSize + 'px' }" [ngClass]="{ 'p-multiselect-option': true, 'p-disabled': disabled, 'p-focus': focused }" [id]="id" [attr.aria-label]="label" [attr.aria-setsize]="ariaSetSize" [attr.aria-posinset]="ariaPosInset" [attr.aria-selected]="selected" [attr.data-p-focused]="focused" [attr.data-p-highlight]="selected" [attr.data-p-disabled]="disabled" [attr.aria-checked]="selected" (click)="onOptionClick($event)" (mouseenter)="onOptionMouseEnter($event)" > <p-checkbox [ngModel]="selected" [binary]="true" [tabindex]="-1" [variant]="variant" [ariaLabel]="label"> <ng-container *ngIf="itemCheckboxIconTemplate"> <ng-template #checkboxicon let-klass="class"> <ng-template *ngTemplateOutlet="itemCheckboxIconTemplate; context: { checked: selected, class: klass }"></ng-template> </ng-template> </ng-container> </p-checkbox> <span *ngIf="!template">{{ label ?? 'empty' }}</span> <ng-container *ngTemplateOutlet="template; context: { $implicit: option }"></ng-container> </li> `, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: Checkbox, selector: "p-checkbox, p-checkBox, p-check-box", inputs: ["value", "name", "disabled", "binary", "ariaLabelledBy", "ariaLabel", "tabindex", "inputId", "style", "inputStyle", "styleClass", "inputClass", "indeterminate", "size", "formControl", "checkboxIcon", "readonly", "required", "autofocus", "trueValue", "falseValue", "variant"], outputs: ["onChange", "onFocus", "onBlur"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: Ripple, selector: "[pRipple]" }, { kind: "ngmodule", type: SharedModule }], encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: MultiSelectItem, decorators: [{ type: Component, args: [{ selector: 'p-multiSelectItem, p-multiselect-item', standalone: true, imports: [CommonModule, Checkbox, FormsModule, Ripple, SharedModule], template: ` <li pRipple role="option" [ngStyle]="{ height: itemSize + 'px' }" [ngClass]="{ 'p-multiselect-option': true, 'p-disabled': disabled, 'p-focus': focused }" [id]="id" [attr.aria-label]="label" [attr.aria-setsize]="ariaSetSize" [attr.aria-posinset]="ariaPosInset" [attr.aria-selected]="selected" [attr.data-p-focused]="focused" [attr.data-p-highlight]="selected" [attr.data-p-disabled]="disabled" [attr.aria-checked]="selected" (click)="onOptionClick($event)" (mouseenter)="onOptionMouseEnter($event)" > <p-checkbox [ngModel]="selected" [binary]="true" [tabindex]="-1" [variant]="variant" [ariaLabel]="label"> <ng-container *ngIf="itemCheckboxIconTemplate"> <ng-template #checkboxicon let-klass="class"> <ng-template *ngTemplateOutlet="itemCheckboxIconTemplate; context: { checked: selected, class: klass }"></ng-template> </ng-template> </ng-container> </p-checkbox> <span *ngIf="!template">{{ label ?? 'empty' }}</span> <ng-container *ngTemplateOutlet="template; context: { $implicit: option }"></ng-container> </li> `, encapsulation: ViewEncapsulation.None }] }], propDecorators: { id: [{ type: Input }], option: [{ type: Input }], selected: [{ type: Input, args: [{ transform: booleanAttribute }] }], label: [{ type: Input }], disabled: [{ type: Input, args: [{ transform: booleanAttribute }] }], itemSize: [{ type: Input, args: [{ transform: numberAttribute }] }], focused: [{ type: Input, args: [{ transform: booleanAttribute }] }], ariaPosInset: [{ type: Input }], ariaSetSize: [{ type: Input }], variant: [{ type: Input }], template: [{ type: Input }], checkIconTemplate: [{ type: Input }], itemCheckboxIconTemplate: [{ type: Input }], onClick: [{ type: Output }], onMouseEnter: [{ type: Output }] } }); // @ts-ignore /** * MultiSelect is used to select multiple items from a collection. * @group Components */ class MultiSelect extends BaseComponent { zone; filterService; overlayService; /** * Unique identifier of the component * @group Props */ id; /** * Defines a string that labels the input for accessibility. * @group Props */ ariaLabel; /** * Inline style of the element. * @group Props */ style; /** * Style class of the element. * @group Props */ styleClass; /** * Inline style of the overlay panel. * @group Props */ panelStyle; /** * Style class of the overlay panel element. * @group Props */ panelStyleClass; /** * Identifier of the focus input to match a label defined for the component. * @group Props */ inputId; /** * When present, it specifies that the element should be disabled. * @group Props */ disabled; /** * Spans 100% width of the container when enabled. * @group Props */ fluid; /** * When present, it specifies that the component cannot be edited. * @group Props */ readonly; /** * Whether to display options as grouped when nested options are provided. * @group Props */ group; /** * When specified, displays an input field to filter the items on keyup. * @group Props */ filter = true; /** * Defines placeholder of the filter input. * @group Props */ filterPlaceHolder; /** * Locale to use in filtering. The default locale is the host environment's current locale. * @group Props */ filterLocale; /** * Specifies the visibility of the options panel. * @group Props */ overlayVisible; /** * Index of the element in tabbing order. * @group Props */ tabindex = 0; /** * Specifies the input variant of the component. * @group Props */ variant; /** * Target element to attach the overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name). * @group Props */ appendTo; /** * A property to uniquely identify a value in options. * @group Props */ dataKey; /** * Name of the input element. * @group Props */ name; /** * Establishes relationships between the component and label(s) where its value should be one or more element IDs. * @group Props */ ariaLabelledBy; /** * Whether to show labels of selected item labels or use default label. * @group Props * @defaultValue true */ set displaySelectedLabel(val) { this._displaySelectedLabel = val; } get displaySelectedLabel() { return this._displaySelectedLabel; } /** * Decides how many selected item labels to show at most. * @group Props * @defaultValue 3 */ set maxSelectedLabels(val) { this._maxSelectedLabels = val; } get maxSelectedLabels() { return this._maxSelectedLabels; } /** * Decides how many selected item labels to show at most. * @group Props */ selectionLimit; /** * Label to display after exceeding max selected labels e.g. ({0} items selected), defaults "ellipsis" keyword to indicate a text-overflow. * @group Props */ selectedItemsLabel; /** * Whether to show the checkbox at header to toggle all items at once. * @group Props */ showToggleAll = true; /** * Text to display when filtering does not return any results. * @group Props */ emptyFilterMessage = ''; /** * Text to display when there is no data. Defaults to global value in i18n translation configuration. * @group Props */ emptyMessage = ''; /** * Clears the filter value when hiding the dropdown. * @group Props */ resetFilterOnHide = false; /** * Icon class of the dropdown icon. * @group Props */ dropdownIcon; /** * Icon class of the chip icon. * @group Props */ chipIcon; /** * Name of the label field of an option. * @group Props */ optionLabel; /** * Name of the value field of an option. * @group Props */ optionValue; /** * Name of the disabled field of an option. * @group Props */ optionDisabled; /** * Name of the label field of an option group. * @group Props */ optionGroupLabel = 'label'; /** * Name of the options field of an option group. * @group Props */ optionGroupChildren = 'items'; /** * Whether to show the header. * @group Props */ showHeader = true; /** * When filtering is enabled, filterBy decides which field or fields (comma separated) to search against. * @group Props */ filterBy; /** * Height of the viewport in pixels, a scrollbar is defined if height of list exceeds this value. * @group Props */ scrollHeight = '200px'; /** * Defines if data is loaded and interacted with in lazy manner. * @group Props */ lazy = false; /** * Whether the data should be loaded on demand during scroll. * @group Props */ virtualScroll; /** * Whether the multiselect is in loading state. * @group Props */ loading = false; /** * Height of an item in the list for VirtualScrolling. * @group Props */ virtualScrollItemSize; /** * Icon to display in loading state. * @group Props */ loadingIcon; /** * Whether to use the scroller feature. The properties of scroller component can be used like an object in it. * @group Props */ virtualScrollOptions; /** * Whether to use overlay API feature. The properties of overlay API can be used like an object in it. * @group Props */ overlayOptions; /** * Defines a string that labels the filter input. * @group Props */ ariaFilterLabel; /** * Defines how the items are filtered. * @group Props */ filterMatchMode = 'contains'; /** * Advisory information to display in a tooltip on hover. * @group Props */ tooltip = ''; /** * Position of the tooltip. * @group Props */ tooltipPosition = 'right'; /** * Type of CSS position. * @group Props */ tooltipPositionStyle = 'absolute'; /** * Style class of the tooltip. * @group Props */ tooltipStyleClass; /** * Applies focus to the filter element when the overlay is shown. * @group Props */ autofocusFilter = false; /** * Defines how the selected items are displayed. * @group Props */ display = 'comma'; /** * Defines the autocomplete is active. * @group Props */ autocomplete = 'off'; /** * Defines the size of the component. * @group Props */ size; /** * When enabled, a clear icon is displayed to clear the value. * @group Props */ showClear = false; /** * When present, it specifies that the component should automatically get focus on load. * @group Props */ autofocus; /** * @deprecated since v14.2.0, use overlayOptions property instead. * Whether to automatically manage layering. * @group Props */ get autoZIndex() { return this._autoZIndex; } set autoZIndex(val) { this._autoZIndex = val; console.log('The autoZIndex property is deprecated since v14.2.0, use overlayOptions property instead.'); } /** * @deprecated since v14.2.0, use overlayOptions property instead. * Base zIndex value to use in layering. * @group Props */ get baseZIndex() { return this._baseZIndex; } set baseZIndex(val) { this._baseZIndex = val; console.log('The baseZIndex property is deprecated since v14.2.0, use overlayOptions property instead.'); } /** * Transition options of the show animation. * @group Props * @deprecated since v14.2.0, use overlayOptions property instead. */ get showTransitionOptions() { return this._showTransitionOptions; } set showTransitionOptions(val) { this._showTransitionOptions = val; console.log('The showTransitionOptions property is deprecated since v14.2.0, use overlayOptions property instead.'); } /** * Transition options of the hide animation. * @group Props * @deprecated since v14.2.0, use overlayOptions property instead. */ get hideTransitionOptions() { return this._hideTransitionOptions; } set hideTransitionOptions(val) { this._hideTransitionOptions = val; console.log('The hideTransitionOptions property is deprecated since v14.2.0, use overlayOptions property instead.'); } /** * Label to display when there are no selections. * @group Props * @deprecated Use placeholder instead. */ set defaultLabel(val) { this._defaultLabel = val; console.log('defaultLabel property is deprecated since 16.6.0, use placeholder instead'); } get defaultLabel() { return this._defaultLabel; } /** * Label to display when there are no selections. * @group Props */ set placeholder(val) { this._placeholder.set(val); } get placeholder() { return this._placeholder.asReadonly(); } /** * An array of objects to display as the available options. * @group Props */ get options() { return this._options(); } set options(val) { if (!deepEquals(this._options(), val)) { this._options.set(val); } } /** * When specified, filter displays with this value. * @group Props */ get filterValue() { return this._filterValue(); } set filterValue(val) { this._filterValue.set(val); } /** * Item size of item to be virtual scrolled. * @group Props * @deprecated use virtualScrollItemSize property instead. */ get itemSize() { return this._itemSize; } set itemSize(val) { this._itemSize = val; console.log('The itemSize property is deprecated, use virtualScrollItemSize property instead.'); } /** * Whether all data is selected. * @group Props */ get selectAll() { return this._selectAll; } set selectAll(value) { this._selectAll = value; } /** * Indicates whether to focus on options when hovering over them, defaults to optionLabel. * @group Props */ focusOnHover = true; /** * Fields used when filtering the options, defaults to optionLabel. * @group Props */ filterFields; /** * Determines if the option will be selected on focus. * @group Props */ selectOnFocus = false; /** * Whether to focus on the first visible or selected element when the overlay panel is shown. * @group Props */ autoOptionFocus = false; /** * Callback to invoke when value changes. * @param {MultiSelectChangeEvent} event - Custom change event. * @group Emits */ onChange = new EventEmitter(); /** * Callback to invoke when data is filtered. * @param {MultiSelectFilterEvent} event - Custom filter event. * @group Emits */ onFilter = new EventEmitter(); /** * Callback to invoke when multiselect receives focus. * @param {MultiSelectFocusEvent} event - Custom focus event. * @group Emits */ onFocus = new EventEmitter(); /** * Callback to invoke when multiselect loses focus. * @param {MultiSelectBlurEvent} event - Custom blur event. * @group Emits */ onBlur = new EventEmitter(); /** * Callback to invoke when component is clicked. * @param {Event} event - Browser event. * @group Emits */ onClick = new EventEmitter(); /** * Callback to invoke when input field is cleared. * @group Emits */ onClear = new EventEmitter(); /** * Callback to invoke when overlay panel becomes visible. * @param {AnimationEvent} event - Animation event. * @group Emits */ onPanelShow = new EventEmitter(); /** * Callback to invoke when overlay panel becomes hidden. * @param {AnimationEvent} event - Animation event. * @group Emits */ onPanelHide = new EventEmitter(); /** * Callback to invoke in lazy mode to load new data. * @param {MultiSelectLazyLoadEvent} event - Lazy load event. * @group Emits */ onLazyLoad = new EventEmitter(); /** * Callback to invoke in lazy mode to load new data. * @param {MultiSelectRemoveEvent} event - Remove event. * @group Emits */ onRemove = new EventEmitter(); /** * Callback to invoke when all data is selected. * @param {MultiSelectSelectAllChangeEvent} event - Custom select event. * @group Emits */ onSelectAllChange = new EventEmitter(); overlayViewChild; filterInputChild; focusInputViewChild; itemsViewChild; scroller; lastHiddenFocusableElementOnOverlay; firstHiddenFocusableElementOnOverlay; headerCheckboxViewChild; footerFacet; headerFacet; _componentStyle = inject(MultiSelectStyle); searchValue; searchTimeout; _selectAll = null; _autoZIndex; _baseZIndex; _showTransitionOptions; _hideTransitionOptions; _defaultLabel; _placeholder = signal(undefined); _itemSize; _selectionLimit; _disableTooltip = false; value; _filteredOptions; onModelChange = () => { }; onModelTouched = () => { }; valuesAsString; focus; filtered; itemTemplate; groupTemplate; loaderTemplate; headerTemplate; filterTemplate; footerTemplate; emptyFilterTemplate; emptyTemplate; selectedItemsTemplate; checkIconTemplate; loadingIconTemplate; filterIconTemplate; removeTokenIconTemplate; chipIconTemplate; clearIconTemplate; dropdownIconTemplate; itemCheckboxIconTemplate; headerCheckboxIconTemplate; templates; _itemTemplate; _groupTemplate; _loaderTemplate; _headerTemplate; _filterTemplate; _footerTemplate; _emptyFilterTemplate; _emptyTemplate; _selectedItemsTemplate; _checkIconTemplate; _loadingIconTemplate; _filterIconTemplate; _removeTokenIconTemplate; _chipIconTemplate; _clearIconTemplate; _dropdownIconTemplate; _itemCheckboxIconTemplate; _headerCheckboxIconTemplate; ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'item': this._itemTemplate = item.template; break; case 'group': this._groupTemplate = item.template; break; case 'selectedItems': case 'selecteditems': this._selectedItemsTemplate = item.template; break; case 'header': this._headerTemplate = item.template; break; case 'filter': this._filterTemplate = item.template; break; case 'emptyfilter': this._emptyFilterTemplate = item.template; break; case 'empty': this._emptyTemplate = item.template; break; case 'footer': this._footerTemplate = item.template; break; case 'loader': this._loaderTemplate = item.template; break; case 'checkicon': this._checkIconTemplate = item.template; console.warn('checkicon is deprecated and will removed in future. Use itemcheckboxicon or headercheckboxicon templates instead.'); break; case 'headercheckboxicon': this._headerCheckboxIconTemplate = item.template; break; case 'loadingicon': this._loadingIconTemplate = item.template; break; case 'filtericon': this._filterIconTemplate = item.template; break; case 'removetokenicon': this._removeTokenIconTemplate = item.template; break; case 'clearicon': this._clearIconTemplate = item.template; break; case 'dropdownicon': this._dropdownIconTemplate = item.template; break; case 'itemcheckboxicon': this._itemCheckboxIconTemplate = item.template; break; case 'chipicon': this._chipIconTemplate = item.template; break; default: this._itemTemplate = item.template; break; } }); } headerCheckboxFocus; filterOptions; preventModelTouched; preventDocumentDefault; focused = false; itemsWrapper; _displaySelectedLabel = true; _maxSelectedLabels = 3; modelValue = signal(null); _filterValue = signal(null); _options = signal(null); startRangeIndex = signal(-1); focusedOptionIndex = signal(-1); selectedOptions; clickInProgress = false; get hostClasses() { const classes = []; if (typeof this.rootClass === 'string') { classes.push(this.rootClass); } else if (Array.isArray(this.rootClass)) { classes.push(...this.rootClass); } else if (typeof this.rootClass === 'object') { Object.keys(this.rootClass) .filter((key) => this.rootClass[key]) .forEach((key) => classes.push(key)); } if (this.styleClass) { classes.push(this.styleClass); } return classes.join(' '); } get rootClass() { return this._componentStyle.classes.root({ instance: this }); } get labelClass() { return this._componentStyle.classes.label({ instance: this }); } get emptyMessageLabel() { return this.emptyMessage || this.config.getTranslation(TranslationKeys.EMPTY_MESSAGE); } get emptyFilterMessageLabel() { return this.emptyFilterMessage || this.config.getTranslation(TranslationKeys.EMPTY_FILTER_MESSAGE); } get filled() { if (typeof this.modelValue() === 'string') return !!this.modelValue(); return isNotEmpty(this.modelValue()); } get isVisibleClearIcon() { return this.modelValue() != null && this.modelValue() !== '' && isNotEmpty(this.modelValue()) && this.showClear && !this.disabled && !this.readonly && this.filled; } get toggleAllAriaLabel() { return this.config.translation.aria ? this.config.translation.aria[this.allSelected() ? 'selectAll' : 'unselectAll'] : undefined; } get closeAriaLabel() { return this.config.translation.aria ? this.config.translation.aria.close : undefined; } get listLabel() { return this.config.getTranslation(TranslationKeys.ARIA)['listLabel']; } get hasFluid() { const nativeElement = this.el.nativeElement; const fluidComponent = nativeElement.closest('p-fluid'); return this.fluid || !!fluidComponent; } getAllVisibleAndNonVisibleOptions() { return this.group ? this.flatOptions(this.options) : this.options || []; } visibleOptions = computed(() => { const options = this.getAllVisibleAndNonVisibleOptions(); const isArrayOfObjects = isArray(options) && ObjectUtils.isObject(options[0]); if (this._filterValue()) { let filteredOptions; if (isArrayOfObjects) { filteredOptions = this.filterService.filter(options, this.searchFields(), this._filterValue(), this.filterMatchMode, this.filterLocale); } else { filteredOptions = options.filter((option) => option.toString().toLocaleLowerCase().includes(this._filterValue().toLocaleLowerCase())); } if (this.group) { const optionGroups = this.options || []; const filtered = []; optionGroups.forEach((group) => { const groupChildren = this.getOptionGroupChildren(group); const filteredItems = groupChildren.filter((item) => filteredOptions.includes(item)); if (filteredItems.length > 0) filtered.push({ ...group, [typeof this.optionGroupChildren === 'string' ? this.optionGroupChildren : 'items']: [...filteredItems] }); }); return this.flatOptions(filtered); } return filteredOptions; } return options; }); label = computed(() => { let label; const modelValue = this.modelValue(); if (modelValue && modelValue.length && this.displaySelectedLabel) { if (isNotEmpty(this.maxSelectedLabels) && modelValue.length > this.maxSelectedLabels) { return this.getSelectedItemsLabel(); } else { label = ''; for (let i = 0; i < modelValue.length; i++) { if (i !== 0) { label += ', '; } label += this.getLabelByValue(modelValue[i]); } } } else { label = this.placeholder() || this.defaultLabel || ''; } return label; }); chipSelectedItems = computed(() => { return isNotEmpty(this.maxSelectedLabels) && this.modelValue() && this.modelValue().length > this.maxSelectedLabels ? this.modelValue().slice(0, this.maxSelectedLabels) : this.modelValue(); }); constructor(zone, filterService, overlayService) { super(); this.zone = zone; this.filterService = filterService; this.overlayService = overlayService; effect(() => { const modelValue = this.modelValue(); const allVisibleAndNonVisibleOptions = this.getAllVisibleAndNonVisibleOptions(); if (allVisibleAndNonVisibleOptions && isNotEmpty(allVisibleAndNonVisibleOptions)) { if (this.optionValue && this.optionLabel && modelValue) { this.selectedOptions = allVisibleAndNonVisibleOptions.filter((option) => modelValue.includes(option[this.optionLabel]) || modelValue.includes(option[this.optionValue])); } else { this.selectedOptions = modelValue; } this.cd.markForCheck(); } }); } ngOnInit() { super.ngOnInit(); this.id = this.id || uuid('pn_id_'); this.autoUpdateModel(); if (this.filterBy) { this.filterOptions = { filter: (value) => this.onFilterInputChange(value), reset: () => this.resetFilter() }; } } maxSelectionLimitReached() { return this.selectionLimit && this.modelValue() && this.modelValue().length === this.selectionLimit; } ngAfterViewInit() { super.ngAfterViewInit(); if (this.overlayVisible) { this.show(); } } ngAfterViewChecked() { if (this.filtered) { this.zone.runOutsideAngular(() => { setTimeout(() => { this.overlayViewChild?.alignOverlay(); }, 1); }); this.filtered = false; } } flatOptions(options) { return (options || []).reduce((result, option, index) => { result.push({ optionGroup: option, group: true, index }); const optionGroupChildren = this.getOptionGroupChildren(option); optionGroupChildren && optionGroupChildren.forEach((o) => result.push(o)); return result; }, []); } autoUpdateModel() { if (this.selectOnFocus && this.autoOptionFocus && !this.hasSelectedOption()) { this.focusedOptionIndex.set(this.findFirstFocusedOptionIndex()); const value = this.getOptionValue(this.visibleOptions()[this.focusedOptionIndex()]); this.onOptionSelect({ originalEvent: null, option: [value] }); } } /** * Updates the model value. * @group Method */ updateModel(value, event) { this.value = value; this.onModelChange(value); this.modelValue.set(value); } onInputClick(event) { event.stopPropagation(); event.preventDefault(); this.focusedOptionIndex.set(-1); } onOptionSelect(event, isFocus = false, index = -1) { const { originalEvent, option } = event; if (this.disabled || this.isOptionDisabled(option)) { return; } let selected = this.isSelected(option); let value = null; if (selected) { value = this.modelValue().filter((val) => !equals(val, this.getOptionValue(option), this.equalityKey())); } else { value = [...(this.modelValue() || []), this.getOptionValue(option)]; } this.updateModel(value, originalEvent); index !== -1 && this.focusedOptionIndex.set(index); isFocus && focus(this.focusInputViewChild?.nativeElement); this.onChange.emit({ originalEvent: event, value: value, itemValue: option }); } findSelectedOptionIndex() { return this.hasSelectedOption() ? this.visibleOptions().findIndex((option) => this.isValidSelectedOption(option)) : -1; } onOptionSelectRange(event, start = -1, end = -1) { start === -1 && (start = this.findNearestSelectedOptionIndex(end, true)); end === -1 && (end = this.findNearestSelectedOptionIndex(start)); if (start !== -1 && end !== -1) { const rangeStart = Math.min(start, end); const rangeEnd = Math.max(start, end); const value = this.visibleOptions() .slice(rangeStart, rangeEnd + 1) .filter((option) => this.isValidOption(option)) .map((option) => this.getOptionValue(option)); this.updateModel(value, event); } } searchFields() { return (this.filterBy || this.optionLabel || 'label').split(','); } findNearestSelectedOptionIndex(index, firstCheckUp = false) { let matchedOptionIndex = -1; if (this.hasSelectedOption()) { if (firstCheckUp) { matchedOptionIndex = this.findPrevSelectedOptionIndex(index); matchedOptionIndex = matchedOptionIndex === -1 ? this.findNextSelectedOptionIndex(index) : matchedOptionIndex; } else { matchedOptionIndex = this.findNextSelectedOptionIndex(index); matchedOptionIndex = matchedOptionIndex === -1 ? this.findPrevSelectedOptionIndex(index) : matchedOptionIndex; } } return matchedOptionIndex > -1 ? matchedOptionIndex : index; } findPrevSelectedOptionIndex(index) { const matchedOptionIndex = this.hasSelectedOption() && index > 0 ? findLastIndex(this.visibleO