UNPKG

primevue

Version:

PrimeVue is a premium UI library for Vue featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, wh

1,255 lines (1,250 loc) 62.4 kB
import Blank from '@primeicons/vue/blank'; import Check from '@primeicons/vue/check'; import ChevronDown from '@primeicons/vue/chevron-down'; import Search from '@primeicons/vue/search'; import Spinner from '@primeicons/vue/spinner'; import Times from '@primeicons/vue/times'; import { cn } from '@primeuix/utils'; import { findSingle, getFocusableElements, isVisible, focus, isTouchDevice, relativePosition, getOuterWidth, absolutePosition, addStyle, getLastFocusableElement, getFirstFocusableElement, isAndroid } from '@primeuix/utils/dom'; import { isNotEmpty, equals, findLastIndex, isPrintableCharacter, resolveFieldData } from '@primeuix/utils/object'; import { ZIndex } from '@primeuix/utils/zindex'; import { FilterService } from '@primevue/core/api'; import { ConnectedOverlayScrollHandler } from '@primevue/core/utils'; import IconField from 'primevue/iconfield'; import InputIcon from 'primevue/inputicon'; import InputText from 'primevue/inputtext'; import OverlayEventBus from 'primevue/overlayeventbus'; import Portal from 'primevue/portal'; import Ripple from 'primevue/ripple'; import VirtualScroller from 'primevue/virtualscroller'; import BaseInput from '@primevue/core/baseinput'; import SelectStyle from 'primevue/select/style'; import { resolveComponent, resolveDirective, openBlock, createElementBlock, mergeProps, renderSlot, createTextVNode, toDisplayString, normalizeClass, createBlock, resolveDynamicComponent, createCommentVNode, createElementVNode, createVNode, withCtx, Transition, normalizeProps, createSlots, Fragment, renderList, withDirectives, withModifiers } from 'vue'; var script$1 = { name: 'BaseSelect', "extends": BaseInput, props: { options: Array, optionLabel: [String, Function], optionValue: [String, Function], optionDisabled: [String, Function], optionGroupLabel: [String, Function], optionGroupChildren: [String, Function], scrollHeight: { type: String, "default": '14rem' }, filter: Boolean, filterPlaceholder: String, filterLocale: String, filterMatchMode: { type: String, "default": 'contains' }, filterFields: { type: Array, "default": null }, editable: Boolean, placeholder: { type: String, "default": null }, dataKey: null, showClear: { type: Boolean, "default": false }, inputId: { type: String, "default": null }, inputClass: { type: [String, Object], "default": null }, inputStyle: { type: Object, "default": null }, labelId: { type: String, "default": null }, labelClass: { type: [String, Object], "default": null }, labelStyle: { type: Object, "default": null }, overlayStyle: { type: Object, "default": null }, overlayClass: { type: [String, Object], "default": null }, appendTo: { type: [String, Object], "default": 'body' }, loading: { type: Boolean, "default": false }, clearIcon: { type: String, "default": undefined }, dropdownIcon: { type: String, "default": undefined }, filterIcon: { type: String, "default": undefined }, loadingIcon: { type: String, "default": undefined }, resetFilterOnHide: { type: Boolean, "default": false }, resetFilterOnClear: { type: Boolean, "default": false }, virtualScrollerOptions: { type: Object, "default": null }, autoOptionFocus: { type: Boolean, "default": false }, autoFilterFocus: { type: Boolean, "default": false }, selectOnFocus: { type: Boolean, "default": false }, focusOnHover: { type: Boolean, "default": true }, highlightOnSelect: { type: Boolean, "default": true }, checkmark: { type: Boolean, "default": false }, multiple: { type: Boolean, "default": false }, filterMessage: { type: String, "default": null }, selectionMessage: { type: String, "default": null }, emptySelectionMessage: { type: String, "default": null }, emptyFilterMessage: { type: String, "default": null }, emptyMessage: { type: String, "default": null }, tabindex: { type: Number, "default": 0 }, ariaLabel: { type: String, "default": null }, ariaLabelledby: { type: String, "default": null } }, style: SelectStyle, provide: function provide() { return { $pcSelect: this, $parentInstance: this }; } }; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var script = { name: 'Select', "extends": script$1, inheritAttrs: false, emits: ['change', 'focus', 'blur', 'before-show', 'before-hide', 'show', 'hide', 'filter'], outsideClickListener: null, scrollHandler: null, resizeListener: null, labelClickListener: null, matchMediaOrientationListener: null, overlay: null, list: null, virtualScroller: null, searchTimeout: null, searchValue: null, isModelValueChanged: false, data: function data() { return { clicked: false, focused: false, focusedOptionIndex: -1, filterValue: null, overlayVisible: false, queryOrientation: null }; }, watch: { modelValue: function modelValue() { this.isModelValueChanged = true; }, options: function options() { this.autoUpdateModel(); } }, mounted: function mounted() { this.autoUpdateModel(); this.bindLabelClickListener(); this.bindMatchMediaOrientationListener(); }, updated: function updated() { if (this.overlayVisible && this.isModelValueChanged) { this.scrollInView(this.findSelectedOptionIndex()); } this.isModelValueChanged = false; }, beforeUnmount: function beforeUnmount() { this.unbindOutsideClickListener(); this.unbindResizeListener(); this.unbindLabelClickListener(); this.unbindMatchMediaOrientationListener(); if (this.scrollHandler) { this.scrollHandler.destroy(); this.scrollHandler = null; } if (this.overlay) { ZIndex.clear(this.overlay); this.overlay = null; } }, methods: { getOptionIndex: function getOptionIndex(index, fn) { return this.virtualScrollerDisabled ? index : fn && fn(index)['index']; }, getOptionLabel: function getOptionLabel(option) { return this.optionLabel ? resolveFieldData(option, this.optionLabel) : option; }, getOptionValue: function getOptionValue(option) { return this.optionValue ? resolveFieldData(option, this.optionValue) : option; }, getOptionRenderKey: function getOptionRenderKey(option, index) { return (this.dataKey ? resolveFieldData(option, this.dataKey) : this.getOptionLabel(option)) + '_' + index; }, getPTItemOptions: function getPTItemOptions(option, itemOptions, index, key) { return this.ptm(key, { context: { option: option, index: index, selected: this.isSelected(option), focused: this.focusedOptionIndex === this.getOptionIndex(index, itemOptions), disabled: this.isOptionDisabled(option) } }); }, isOptionDisabled: function isOptionDisabled(option) { return this.optionDisabled ? resolveFieldData(option, this.optionDisabled) : false; }, isOptionGroup: function isOptionGroup(option) { return this.optionGroupLabel && option.optionGroup && option.group; }, getOptionGroupLabel: function getOptionGroupLabel(optionGroup) { return resolveFieldData(optionGroup, this.optionGroupLabel); }, getOptionGroupChildren: function getOptionGroupChildren(optionGroup) { return resolveFieldData(optionGroup, this.optionGroupChildren); }, getAriaPosInset: function getAriaPosInset(index) { var _this = this; return (this.optionGroupLabel ? index - this.visibleOptions.slice(0, index).filter(function (option) { return _this.isOptionGroup(option); }).length : index) + 1; }, show: function show(isFocus) { this.$emit('before-show'); this.overlayVisible = true; this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : this.editable ? -1 : this.findSelectedOptionIndex(); isFocus && focus(this.$refs.focusInput); }, hide: function hide(isFocus) { var _this2 = this; var _hide = function _hide() { _this2.$emit('before-hide'); _this2.overlayVisible = false; _this2.clicked = false; _this2.focusedOptionIndex = -1; _this2.searchValue = ''; _this2.resetFilterOnHide && (_this2.filterValue = null); isFocus && focus(_this2.$refs.focusInput); }; setTimeout(function () { _hide(); }, 0); // For ScreenReaders }, onFocus: function onFocus(event) { if (this.disabled) { // For ScreenReaders return; } this.focused = true; if (this.overlayVisible) { this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : this.editable ? -1 : this.findSelectedOptionIndex(); this.scrollInView(this.focusedOptionIndex); } this.$emit('focus', event); }, onBlur: function onBlur(event) { var _this3 = this; setTimeout(function () { var _this3$formField$onBl, _this3$formField; _this3.focused = false; _this3.focusedOptionIndex = -1; _this3.searchValue = ''; _this3.$emit('blur', event); (_this3$formField$onBl = (_this3$formField = _this3.formField).onBlur) === null || _this3$formField$onBl === void 0 || _this3$formField$onBl.call(_this3$formField, event); }, 100); }, onKeyDown: function onKeyDown(event) { var _this4 = this; if (this.disabled) { event.preventDefault(); return; } if (isAndroid()) { switch (event.code) { case 'Backspace': this.onBackspaceKey(event, this.editable); break; case 'Enter': case 'NumpadDecimal': this.onEnterKey(event); break; default: event.preventDefault(); return; } } var metaKey = event.metaKey || event.ctrlKey; switch (event.code) { case 'ArrowDown': this.onArrowDownKey(event); break; case 'ArrowUp': this.onArrowUpKey(event, this.editable); break; case 'ArrowLeft': case 'ArrowRight': this.onArrowLeftKey(event, this.editable); break; case 'Home': this.onHomeKey(event, this.editable); break; case 'End': this.onEndKey(event, this.editable); break; case 'PageDown': this.onPageDownKey(event); break; case 'PageUp': this.onPageUpKey(event); break; case 'Space': this.onSpaceKey(event, this.editable); break; case 'Enter': case 'NumpadEnter': this.onEnterKey(event); break; case 'Escape': this.onEscapeKey(event); break; case 'Tab': this.onTabKey(event); break; case 'Backspace': this.onBackspaceKey(event, this.editable); break; case 'ShiftLeft': case 'ShiftRight': //NOOP break; default: if (!metaKey && isPrintableCharacter(event.key)) { !this.overlayVisible && this.show(); !this.editable && this.searchOptions(event, event.key); if (this.filter) { this.$nextTick(function () { if (_this4.$refs.filterInput) { focus(_this4.$refs.filterInput.$el); } }); } } break; } this.clicked = false; }, onEditableInput: function onEditableInput(event) { var value = event.target.value; this.searchValue = ''; var matched = this.searchOptions(event, value); !matched && (this.focusedOptionIndex = -1); this.updateModel(event, value); !this.overlayVisible && isNotEmpty(value) && this.show(); }, onContainerClick: function onContainerClick(event) { if (this.disabled || this.loading) { return; } if (event.target.tagName === 'INPUT' || event.target.getAttribute('data-pc-section') === 'clearicon' || event.target.closest('[data-pc-section="clearicon"]')) { return; } else if (!this.overlay || !this.overlay.contains(event.target)) { this.overlayVisible ? this.hide(true) : this.show(true); } this.clicked = true; }, onClearClick: function onClearClick(event) { this.updateModel(event, this.multiple ? [] : null); this.resetFilterOnClear && (this.filterValue = null); }, onFirstHiddenFocus: function onFirstHiddenFocus(event) { var focusableEl = event.relatedTarget === this.$refs.focusInput ? getFirstFocusableElement(this.overlay, ':not([data-p-hidden-focusable="true"])') : this.$refs.focusInput; focus(focusableEl); }, onLastHiddenFocus: function onLastHiddenFocus(event) { var focusableEl = event.relatedTarget === this.$refs.focusInput ? getLastFocusableElement(this.overlay, ':not([data-p-hidden-focusable="true"])') : this.$refs.focusInput; focus(focusableEl); }, onOptionSelect: function onOptionSelect(event, option) { var isHide = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; if (!this.overlayVisible) return; if (this.multiple) { this.onOptionSelectMultiple(event, option); return; } var value = this.getOptionValue(option); this.updateModel(event, value); isHide && this.hide(true); }, onOptionSelectMultiple: function onOptionSelectMultiple(event, option) { var _this5 = this; var value = this.getOptionValue(option); var current = Array.isArray(this.d_value) ? this.d_value : []; var newValue = this.isSelected(option) ? current.filter(function (v) { return !equals(v, value, _this5.equalityKey); }) : [].concat(_toConsumableArray(current), [value]); this.updateModel(event, newValue); }, onOptionMouseMove: function onOptionMouseMove(event, index) { if (this.focusOnHover) { this.changeFocusedOptionIndex(event, index); } }, onFilterChange: function onFilterChange(event) { var value = event.target.value; this.filterValue = value; this.focusedOptionIndex = -1; this.$emit('filter', { originalEvent: event, value: value }); !this.virtualScrollerDisabled && this.virtualScroller.scrollToIndex(0); }, onFilterKeyDown: function onFilterKeyDown(event) { // Check if the event is part of a text composition process (e.g., for Asian languages). // If event.isComposing is true, it means the user is still composing text and the input is not finalized. if (event.isComposing) return; switch (event.code) { case 'ArrowDown': this.onArrowDownKey(event); break; case 'ArrowUp': this.onArrowUpKey(event, true); break; case 'ArrowLeft': case 'ArrowRight': this.onArrowLeftKey(event, true); break; case 'Home': this.onHomeKey(event, true); break; case 'End': this.onEndKey(event, true); break; case 'Enter': case 'NumpadEnter': this.onEnterKey(event); break; case 'Escape': this.onEscapeKey(event); break; case 'Tab': this.onTabKey(event); break; } }, onFilterBlur: function onFilterBlur() { this.focusedOptionIndex = -1; }, onFilterUpdated: function onFilterUpdated() { if (this.overlayVisible) { this.alignOverlay(); } }, onOverlayClick: function onOverlayClick(event) { OverlayEventBus.emit('overlay-click', { originalEvent: event, target: this.$el }); }, onOverlayKeyDown: function onOverlayKeyDown(event) { switch (event.code) { case 'Escape': this.onEscapeKey(event); break; } }, onArrowDownKey: function onArrowDownKey(event) { if (!this.overlayVisible) { this.show(); this.editable && this.changeFocusedOptionIndex(event, this.findSelectedOptionIndex()); } else { var optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex(this.focusedOptionIndex) : this.clicked ? this.findFirstOptionIndex() : this.findFirstFocusedOptionIndex(); this.changeFocusedOptionIndex(event, optionIndex); } event.preventDefault(); }, onArrowUpKey: function onArrowUpKey(event) { var pressedInInputText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (event.altKey && !pressedInInputText) { if (this.focusedOptionIndex !== -1) { this.onOptionSelect(event, this.visibleOptions[this.focusedOptionIndex]); } !this.multiple && this.overlayVisible && this.hide(); event.preventDefault(); } else { var optionIndex = this.focusedOptionIndex !== -1 ? this.findPrevOptionIndex(this.focusedOptionIndex) : this.clicked ? this.findLastOptionIndex() : this.findLastFocusedOptionIndex(); this.changeFocusedOptionIndex(event, optionIndex); !this.overlayVisible && this.show(); event.preventDefault(); } }, onArrowLeftKey: function onArrowLeftKey(event) { var pressedInInputText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; pressedInInputText && (this.focusedOptionIndex = -1); }, onHomeKey: function onHomeKey(event) { var pressedInInputText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (pressedInInputText) { var target = event.currentTarget; if (event.shiftKey) { target.setSelectionRange(0, event.target.selectionStart); } else { target.setSelectionRange(0, 0); this.focusedOptionIndex = -1; } } else { this.changeFocusedOptionIndex(event, this.findFirstOptionIndex()); !this.overlayVisible && this.show(); } event.preventDefault(); }, onEndKey: function onEndKey(event) { var pressedInInputText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (pressedInInputText) { var target = event.currentTarget; if (event.shiftKey) { target.setSelectionRange(event.target.selectionStart, target.value.length); } else { var len = target.value.length; target.setSelectionRange(len, len); this.focusedOptionIndex = -1; } } else { this.changeFocusedOptionIndex(event, this.findLastOptionIndex()); !this.overlayVisible && this.show(); } event.preventDefault(); }, onPageUpKey: function onPageUpKey(event) { this.scrollInView(0); event.preventDefault(); }, onPageDownKey: function onPageDownKey(event) { this.scrollInView(this.visibleOptions.length - 1); event.preventDefault(); }, onEnterKey: function onEnterKey(event) { if (!this.overlayVisible) { this.focusedOptionIndex = -1; // reset this.onArrowDownKey(event); } else { if (this.focusedOptionIndex !== -1) { this.onOptionSelect(event, this.visibleOptions[this.focusedOptionIndex]); } !this.multiple && this.hide(true); } event.preventDefault(); }, onSpaceKey: function onSpaceKey(event) { var pressedInInputText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; !pressedInInputText && this.onEnterKey(event); }, onEscapeKey: function onEscapeKey(event) { this.overlayVisible && this.hide(true); event.preventDefault(); event.stopPropagation(); //@todo will be changed next versionss }, onTabKey: function onTabKey(event) { var pressedInInputText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (!pressedInInputText) { if (this.overlayVisible && this.hasFocusableElements()) { focus(this.$refs.firstHiddenFocusableElementOnOverlay); event.preventDefault(); } else { if (this.focusedOptionIndex !== -1) { this.onOptionSelect(event, this.visibleOptions[this.focusedOptionIndex]); } this.overlayVisible && this.hide(this.filter); } } }, onBackspaceKey: function onBackspaceKey(event) { var pressedInInputText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (pressedInInputText) { !this.overlayVisible && this.show(); } }, onOverlayEnter: function onOverlayEnter(el) { var _this6 = this; ZIndex.set('overlay', el, this.$primevue.config.zIndex.overlay); addStyle(el, { position: 'absolute', top: '0' }); this.alignOverlay(); this.scrollInView(); // Issue: #7508 this.$attrSelector && el.setAttribute(this.$attrSelector, ''); setTimeout(function () { _this6.autoFilterFocus && _this6.filter && _this6.$refs.filterInput && focus(_this6.$refs.filterInput.$el); _this6.autoUpdateModel(); }, 1); }, onOverlayAfterEnter: function onOverlayAfterEnter() { this.bindOutsideClickListener(); this.bindScrollListener(); this.bindResizeListener(); this.$emit('show'); }, onOverlayLeave: function onOverlayLeave(el) { var _this7 = this; el.style.pointerEvents = 'none'; this.unbindOutsideClickListener(); this.unbindScrollListener(); this.unbindResizeListener(); if (this.autoFilterFocus && this.filter && !this.editable) { this.$nextTick(function () { if (_this7.$refs.filterInput) { focus(_this7.$refs.filterInput.$el); } }); } this.$emit('hide'); this.overlay = null; }, onOverlayAfterLeave: function onOverlayAfterLeave(el) { ZIndex.clear(el); }, alignOverlay: function alignOverlay() { if (this.appendTo === 'self') { relativePosition(this.overlay, this.$el); } else { if (this.overlay) { this.overlay.style.minWidth = getOuterWidth(this.$el) + 'px'; absolutePosition(this.overlay, this.$el); } } }, bindOutsideClickListener: function bindOutsideClickListener() { var _this8 = this; if (!this.outsideClickListener) { this.outsideClickListener = function (event) { var composedPath = event.composedPath(); if (_this8.overlayVisible && _this8.overlay && !composedPath.includes(_this8.$el) && !composedPath.includes(_this8.overlay)) { _this8.hide(); } }; document.addEventListener('click', this.outsideClickListener, true); } }, unbindOutsideClickListener: function unbindOutsideClickListener() { if (this.outsideClickListener) { document.removeEventListener('click', this.outsideClickListener, true); this.outsideClickListener = null; } }, bindScrollListener: function bindScrollListener() { var _this9 = this; if (!this.scrollHandler) { this.scrollHandler = new ConnectedOverlayScrollHandler(this.$refs.container, function () { if (_this9.overlayVisible) { _this9.hide(); } }); } this.scrollHandler.bindScrollListener(); }, unbindScrollListener: function unbindScrollListener() { if (this.scrollHandler) { this.scrollHandler.unbindScrollListener(); } }, bindResizeListener: function bindResizeListener() { var _this0 = this; if (!this.resizeListener) { this.resizeListener = function () { if (_this0.overlayVisible && !isTouchDevice()) { _this0.hide(); } }; window.addEventListener('resize', this.resizeListener); } }, unbindResizeListener: function unbindResizeListener() { if (this.resizeListener) { window.removeEventListener('resize', this.resizeListener); this.resizeListener = null; } }, bindLabelClickListener: function bindLabelClickListener() { var _this1 = this; if (!this.editable && !this.labelClickListener) { var label = document.querySelector("label[for=\"".concat(this.labelId || this.inputId, "\"]")); if (label && isVisible(label)) { this.labelClickListener = function () { focus(_this1.$refs.focusInput); }; label.addEventListener('click', this.labelClickListener); } } }, unbindLabelClickListener: function unbindLabelClickListener() { if (this.labelClickListener) { var label = document.querySelector("label[for=\"".concat(this.labelId || this.inputId, "\"]")); if (label && isVisible(label)) { label.removeEventListener('click', this.labelClickListener); } } }, bindMatchMediaOrientationListener: function bindMatchMediaOrientationListener() { var _this10 = this; if (!this.matchMediaOrientationListener) { var query = matchMedia("(orientation: portrait)"); this.queryOrientation = query; this.matchMediaOrientationListener = function () { _this10.alignOverlay(); }; this.queryOrientation.addEventListener('change', this.matchMediaOrientationListener); } }, unbindMatchMediaOrientationListener: function unbindMatchMediaOrientationListener() { if (this.matchMediaOrientationListener) { this.queryOrientation.removeEventListener('change', this.matchMediaOrientationListener); this.queryOrientation = null; this.matchMediaOrientationListener = null; } }, hasFocusableElements: function hasFocusableElements() { return getFocusableElements(this.overlay, ':not([data-p-hidden-focusable="true"])').length > 0; }, isOptionExactMatched: function isOptionExactMatched(option) { var _this$getOptionLabel; return this.isValidOption(option) && typeof this.getOptionLabel(option) === 'string' && ((_this$getOptionLabel = this.getOptionLabel(option)) === null || _this$getOptionLabel === void 0 ? void 0 : _this$getOptionLabel.toLocaleLowerCase(this.filterLocale)) == this.searchValue.toLocaleLowerCase(this.filterLocale); }, isOptionStartsWith: function isOptionStartsWith(option) { var _this$getOptionLabel2; return this.isValidOption(option) && typeof this.getOptionLabel(option) === 'string' && ((_this$getOptionLabel2 = this.getOptionLabel(option)) === null || _this$getOptionLabel2 === void 0 ? void 0 : _this$getOptionLabel2.toLocaleLowerCase(this.filterLocale).startsWith(this.searchValue.toLocaleLowerCase(this.filterLocale))); }, isValidOption: function isValidOption(option) { return isNotEmpty(option) && !(this.isOptionDisabled(option) || this.isOptionGroup(option)); }, isValidSelectedOption: function isValidSelectedOption(option) { return this.isValidOption(option) && this.isSelected(option); }, isSelected: function isSelected(option) { var _this11 = this; var optionValue = this.getOptionValue(option); if (this.multiple) { return Array.isArray(this.d_value) && this.d_value.some(function (v) { return equals(v, optionValue, _this11.equalityKey); }); } return equals(this.d_value, optionValue, this.equalityKey); }, findFirstOptionIndex: function findFirstOptionIndex() { var _this12 = this; return this.visibleOptions.findIndex(function (option) { return _this12.isValidOption(option); }); }, findLastOptionIndex: function findLastOptionIndex() { var _this13 = this; return findLastIndex(this.visibleOptions, function (option) { return _this13.isValidOption(option); }); }, findNextOptionIndex: function findNextOptionIndex(index) { var _this14 = this; var matchedOptionIndex = index < this.visibleOptions.length - 1 ? this.visibleOptions.slice(index + 1).findIndex(function (option) { return _this14.isValidOption(option); }) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex + index + 1 : index; }, findPrevOptionIndex: function findPrevOptionIndex(index) { var _this15 = this; var matchedOptionIndex = index > 0 ? findLastIndex(this.visibleOptions.slice(0, index), function (option) { return _this15.isValidOption(option); }) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex : index; }, findSelectedOptionIndex: function findSelectedOptionIndex() { var _this16 = this; return this.visibleOptions.findIndex(function (option) { return _this16.isValidSelectedOption(option); }); }, findFirstFocusedOptionIndex: function findFirstFocusedOptionIndex() { var selectedIndex = this.findSelectedOptionIndex(); return selectedIndex < 0 ? this.findFirstOptionIndex() : selectedIndex; }, findLastFocusedOptionIndex: function findLastFocusedOptionIndex() { var selectedIndex = this.findSelectedOptionIndex(); return selectedIndex < 0 ? this.findLastOptionIndex() : selectedIndex; }, searchOptions: function searchOptions(event, _char) { var _this17 = this; this.searchValue = (this.searchValue || '') + _char; var optionIndex = -1; var matched = false; if (isNotEmpty(this.searchValue)) { optionIndex = this.visibleOptions.findIndex(function (option) { return _this17.isOptionExactMatched(option); }); if (optionIndex === -1) { optionIndex = this.visibleOptions.findIndex(function (option) { return _this17.isOptionStartsWith(option); }); } if (optionIndex !== -1) { matched = true; } if (optionIndex === -1 && this.focusedOptionIndex === -1) { optionIndex = this.findFirstFocusedOptionIndex(); } if (optionIndex !== -1) { this.changeFocusedOptionIndex(event, optionIndex); } } if (this.searchTimeout) { clearTimeout(this.searchTimeout); } this.searchTimeout = setTimeout(function () { _this17.searchValue = ''; _this17.searchTimeout = null; }, 500); return matched; }, changeFocusedOptionIndex: function changeFocusedOptionIndex(event, index) { if (this.focusedOptionIndex !== index) { this.focusedOptionIndex = index; this.scrollInView(); if (this.selectOnFocus) { this.onOptionSelect(event, this.visibleOptions[index], false); } } }, scrollInView: function scrollInView() { var _this18 = this; var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; this.$nextTick(function () { var id = index !== -1 ? "".concat(_this18.$id, "_").concat(index) : _this18.focusedOptionId; var element = findSingle(_this18.list, "li[id=\"".concat(id, "\"]")); if (element) { element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'nearest' }); } else if (!_this18.virtualScrollerDisabled) { _this18.virtualScroller && _this18.virtualScroller.scrollToIndex(index !== -1 ? index : _this18.focusedOptionIndex); } }); }, autoUpdateModel: function autoUpdateModel() { if (this.autoOptionFocus) { this.focusedOptionIndex = this.findFirstFocusedOptionIndex(); } if (this.selectOnFocus && this.autoOptionFocus && !this.$filled && !this.multiple) { this.onOptionSelect(null, this.visibleOptions[this.focusedOptionIndex], false); } }, updateModel: function updateModel(event, value) { this.writeValue(value, event); this.$emit('change', { originalEvent: event, value: value }); }, flatOptions: function flatOptions(options) { var _this19 = this; return (options || []).reduce(function (result, option, index) { result.push({ optionGroup: option, group: true, index: index }); var optionGroupChildren = _this19.getOptionGroupChildren(option); optionGroupChildren && optionGroupChildren.forEach(function (o) { return result.push(o); }); return result; }, []); }, overlayRef: function overlayRef(el) { this.overlay = el; }, listRef: function listRef(el, contentRef) { this.list = el; contentRef && contentRef(el); // For VirtualScroller }, virtualScrollerRef: function virtualScrollerRef(el) { this.virtualScroller = el; } }, computed: { visibleOptions: function visibleOptions() { var _this20 = this; var options = this.optionGroupLabel ? this.flatOptions(this.options) : this.options || []; if (this.filterValue) { var filteredOptions = FilterService.filter(options, this.searchFields, this.filterValue, this.filterMatchMode, this.filterLocale); if (this.optionGroupLabel) { var optionGroups = this.options || []; var filtered = []; optionGroups.forEach(function (group) { var groupChildren = _this20.getOptionGroupChildren(group); var filteredItems = groupChildren.filter(function (item) { return filteredOptions.includes(item); }); if (filteredItems.length > 0) filtered.push(_objectSpread(_objectSpread({}, group), {}, _defineProperty({}, typeof _this20.optionGroupChildren === 'string' ? _this20.optionGroupChildren : 'items', _toConsumableArray(filteredItems)))); }); return this.flatOptions(filtered); } return filteredOptions; } return options; }, label: function label() { var _this21 = this; if (this.multiple) { if (!Array.isArray(this.d_value) || this.d_value.length === 0) { return this.placeholder || 'p-emptylabel'; } return this.d_value.map(function (val) { var opt = _this21.visibleOptions.find(function (o) { return !_this21.isOptionGroup(o) && equals(val, _this21.getOptionValue(o), _this21.equalityKey); }); return opt ? _this21.getOptionLabel(opt) : String(val); }).filter(Boolean).join(', '); } var selectedOptionIndex = this.findSelectedOptionIndex(); return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions[selectedOptionIndex]) : this.placeholder || 'p-emptylabel'; }, editableInputValue: function editableInputValue() { var selectedOptionIndex = this.findSelectedOptionIndex(); return selectedOptionIndex !== -1 ? this.getOptionLabel(this.visibleOptions[selectedOptionIndex]) : this.d_value || ''; }, equalityKey: function equalityKey() { return this.optionValue ? null : this.dataKey; }, searchFields: function searchFields() { return this.filterFields || [this.optionLabel]; }, filterResultMessageText: function filterResultMessageText() { return isNotEmpty(this.visibleOptions) ? this.filterMessageText.replaceAll('{0}', this.visibleOptions.length) : this.emptyFilterMessageText; }, filterMessageText: function filterMessageText() { return this.filterMessage || this.$primevue.config.locale.searchMessage || ''; }, emptyFilterMessageText: function emptyFilterMessageText() { return this.emptyFilterMessage || this.$primevue.config.locale.emptySearchMessage || this.$primevue.config.locale.emptyFilterMessage || ''; }, emptyMessageText: function emptyMessageText() { return this.emptyMessage || this.$primevue.config.locale.emptyMessage || ''; }, selectionMessageText: function selectionMessageText() { return this.selectionMessage || this.$primevue.config.locale.selectionMessage || ''; }, emptySelectionMessageText: function emptySelectionMessageText() { return this.emptySelectionMessage || this.$primevue.config.locale.emptySelectionMessage || ''; }, selectedMessageText: function selectedMessageText() { var selectedCount = this.multiple ? Array.isArray(this.d_value) ? this.d_value.length : 0 : 1; return this.$filled ? this.selectionMessageText.replaceAll('{0}', String(selectedCount)) : this.emptySelectionMessageText; }, focusedOptionId: function focusedOptionId() { return this.focusedOptionIndex !== -1 ? "".concat(this.$id, "_").concat(this.focusedOptionIndex) : null; }, ariaSetSize: function ariaSetSize() { var _this22 = this; return this.visibleOptions.filter(function (option) { return !_this22.isOptionGroup(option); }).length; }, isClearIconVisible: function isClearIconVisible() { if (!this.showClear || this.disabled || this.loading) return false; if (this.multiple) return Array.isArray(this.d_value) && this.d_value.length > 0; return this.d_value != null; }, virtualScrollerDisabled: function virtualScrollerDisabled() { return !this.virtualScrollerOptions; }, containerDataP: function containerDataP() { return cn(_defineProperty({ invalid: this.$invalid, disabled: this.disabled, focus: this.focused, fluid: this.$fluid, filled: this.$variant === 'filled' }, this.size, this.size)); }, labelDataP: function labelDataP() { return cn(_defineProperty(_defineProperty({ placeholder: !this.editable && this.label === this.placeholder, clearable: this.showClear, disabled: this.disabled, editable: this.editable }, this.size, this.size), "empty", !this.editable && !this.$slots['value'] && (this.label === 'p-emptylabel' || this.label.length === 0 || this.multiple && (!Array.isArray(this.d_value) || this.d_value.length === 0)))); }, dropdownIconDataP: function dropdownIconDataP() { return cn(_defineProperty({}, this.size, this.size)); }, overlayDataP: function overlayDataP() { return cn(_defineProperty({}, 'portal-' + this.appendTo, 'portal-' + this.appendTo)); } }, directives: { ripple: Ripple }, components: { InputText: InputText, VirtualScroller: VirtualScroller, Portal: Portal, InputIcon: InputIcon, IconField: IconField, Times: Times, ChevronDown: ChevronDown, Spinner: Spinner, Search: Search, Check: Check, Blank: Blank } }; var _hoisted_1 = ["id", "data-p"]; var _hoisted_2 = ["name", "id", "value", "placeholder", "tabindex", "disabled", "aria-label", "aria-labelledby", "aria-expanded", "aria-controls", "aria-activedescendant", "aria-invalid", "data-p"]; var _hoisted_3 = ["name", "id", "tabindex", "aria-label", "aria-labelledby", "aria-expanded", "aria-controls", "aria-activedescendant", "aria-invalid", "aria-disabled", "data-p"]; var _hoisted_4 = ["data-p"]; var _hoisted_5 = ["id", "aria-multiselectable"]; var _hoisted_6 = ["id"]; var _hoisted_7 = ["id", "aria-label", "aria-selected", "aria-disabled", "aria-setsize", "aria-posinset", "onMousedown", "onMousemove", "data-p-selected", "data-p-focused", "data-p-disabled"]; function render(_ctx, _cache, $props, $setup, $data, $options) { var _component_Spinner = resolveComponent("Spinner"); var _component_InputText = resolveComponent("InputText"); var _component_Search = resolveComponent("Search"); var _component_InputIcon = resolveComponent("InputIcon"); var _component_IconField = resolveComponent("IconField"); var _component_Check = resolveComponent("Check"); var _component_Blank = resolveComponent("Blank"); var _component_VirtualScroller = resolveComponent("VirtualScroller"); var _component_Portal = resolveComponent("Portal"); var _directive_ripple = resolveDirective("ripple"); return openBlock(), createElementBlock("div", mergeProps({ ref: "container", id: _ctx.$id, "class": _ctx.cx('root'), onClick: _cache[12] || (_cache[12] = function () { return $options.onContainerClick && $options.onContainerClick.apply($options, arguments); }), "data-p": $options.containerDataP }, _ctx.ptmi('root')), [_ctx.editable ? (openBlock(), createElementBlock("input", mergeProps({ key: 0, ref: "focusInput", name: _ctx.name, id: _ctx.labelId || _ctx.inputId, type: "text", "class": [_ctx.cx('label'), _ctx.inputClass, _ctx.labelClass], style: [_ctx.inputStyle, _ctx.labelStyle], value: $options.editableInputValue, placeholder: _ctx.placeholder, tabindex: !_ctx.disabled ? _ctx.tabindex : -1, disabled: _ctx.disabled, autocomplete: "off", role: "combobox", "aria-label": _ctx.ariaLabel, "aria-labelledby": _ctx.ariaLabelledby, "aria-haspopup": "listbox", "aria-expanded": $data.overlayVisible, "aria-controls": $data.overlayVisible ? _ctx.$id + '_list' : undefined, "aria-activedescendant": $data.focused ? $options.focusedOptionId : undefined, "aria-invalid": _ctx.invalid || undefined, onFocus: _cache[0] || (_cache[0] = function () { return $options.onFocus && $options.onFocus.apply($options, arguments); }), onBlur: _cache[1] || (_cache[1] = function () { return $options.onBlur && $options.onBlur.apply($options, arguments); }), onKeydown: _cache[2] || (_cache[2] = function () { return $options.onKeyDown && $options.onKeyDown.apply($options, arguments); }), onInput: _cache[3] || (_cache[3] = function () { return $options.onEditableInput && $options.onEditableInput.apply($options, arguments); }), "data-p": $options.labelDataP }, _ctx.ptm('label')), null, 16, _hoisted_2)) : (openBlock(), createElementBlock("span", mergeProps({ key: 1, ref: "focusInput", name: _ctx.name, id: _ctx.labelId || _ctx.inputId, "class": [_ctx.cx('label'), _ctx.inputClass, _ctx.labelClass], style: [_ctx.inputStyle, _ctx.labelStyle], tabindex: !_ctx.disabled ? _ctx.tabindex : -1, role: "combobox", "aria-label": _ctx.ariaLabel || ($options.label === 'p-emptylabel' ? undefined : $options.label), "aria-labelledby": _ctx.ariaLabelledby, "aria-haspopup": "listbox", "aria-expanded": $data.overlayVisible, "aria-controls": _ctx.$id + '_list', "aria-activedescendant": $data.focused ? $options.focusedOptionId : undefined, "aria-invalid": _ctx.invalid || undefined, "aria-disabled": _ctx.disabled, onFocus: _cache[4] || (_cache[4] = function () { return $options.onFocus && $options.onFocus.apply($options, arguments); }), onBlur: _cache[5] || (_cache[5] = function () { return $options.onBlur && $options.onBlur.apply($options, arguments); }), onKeydown: _cache[6] || (_cache[6] = function () { return $options.onKeyDown && $options.onKeyDown.apply($options, arguments); }), "data-p": $options.labelDataP }, _ctx.ptm('label')), [renderSlot(_ctx.$slots, "value", { value: _ctx.d_value, placeholder: _ctx.placeholder }, function () { var _$options$label; return [createTextVNode(toDisplayString($options.label === 'p-emptylabel' ? ' ' : (_$options$label = $options.label) !== null && _$options$label !== void 0 ? _$options$label : 'empty'), 1)]; })], 16, _hoisted_3)), $options.isClearIconVisible ? renderSlot(_ctx.$slots, "clearicon", { key: 2, "class": normalizeClass(_ctx.cx('clearIcon')), clearCallback: $options.onClearClick }, function () { return [(openBlock(), createBlock(resolveDynamicComponent(_ctx.clearIcon ? 'i' : 'Times'), mergeProps({ ref: "clearIcon", "class": [_ctx.cx('clearIcon'), _ctx.clearIcon], onClick: $options.onClearClick }, _ctx.ptm('clearIcon'), { "data-pc-section": "clearicon" }), null, 16, ["class", "onClick"]))]; }) : createCommentVNode("", true), createElementVNode("div", mergeProps({ "class": _ctx.cx('dropdown') }, _ctx.ptm('dropdown')), [_ctx.loading ? renderSlot(_ctx.$slots, "loadingicon", { key: 0, "class": normalizeClass(_ctx.cx('loadingIcon')) }, function () { return [_ctx.loadingIcon ? (openBlock(), createElementBlock("span", mergeProps({ key: 0, "class": [_ctx.cx('loadingIcon'), 'pi-spin', _ctx.loadingIcon], "aria-hidden": "true" }, _ctx.ptm('loadingIcon')), null, 16)) : (openBlock(), createBlock(_component_Spinner, mergeProps({ key: 1, "class": _ctx.cx('loadingIcon'), spin: "", "aria-hidden": "true" }, _ctx.ptm('loadingIcon')), null, 16, ["class"]))]; }) : renderSlot(_ctx.$slots, "dropdownicon", { key: 1, "class": normalizeClass(_ctx.cx('dropdownIcon')) }, function () { return [(openBlock(), createBlock(resolveDynamicComponent(_ctx.dropdownIcon ? 'span' : 'ChevronDown'), mergeProps({ "class": [_ctx.cx('dropdownIcon'), _ctx.dropdownIcon], "aria-hidden": "true", "data-p": $options.dropdownIconDataP }, _ctx.ptm('dropdownIcon')), null, 16, ["class", "data-p"]))]; })], 16), createVNode(_component_Portal, { appendTo: _ctx.appendTo }, { "default": withCtx(function () { return [createVNode(Transition, mergeProps({ name: "p-anchored-overlay", onEnter: $options.onOverlayEnter, onAfterEnter: $options.onOverlayAfterEnter, onLeave: $options.onOverlayLeave, onAfterLeave: $options.onOverlayAfterLeave }, _ctx.ptm('transition')), { "default": withCtx(function () { return [$data.overlayVisible ? (openBlock(), createElementBlock("div", mergeProps({ key: 0, ref: $options.overlayRef, "class": [_ctx.cx('overlay'), _ctx.overlayClass], style: _ctx.overlayStyle, onClick: _cache[10] || (_cache[10] = function () { return $options.onOverlayClick && $options.onOverlayClick.apply($options, arguments); }), onKeydown: _cache[11] || (_cache[11] = function () { return $options.onOverlayKeyDown && $options.onOverlayKeyDown.apply($options, arguments); }), "data-p": $options.overlayDataP