UNPKG

primereact

Version:

PrimeReact is an open source UI library for React 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 Prime

2 lines (1 loc) 34.4 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/api"),n=require("primereact/componentbase"),r=require("primereact/hooks"),o=require("primereact/icons/chevrondown"),l=require("primereact/icons/chevronup"),i=require("primereact/icons/spinner"),a=require("primereact/icons/times"),c=require("primereact/overlayservice"),u=require("primereact/tooltip"),s=require("primereact/utils"),p=require("primereact/csstransition"),d=require("primereact/icons/search"),f=require("primereact/portal"),m=require("primereact/virtualscroller"),b=require("primereact/ripple"),v=require("primereact/icons/check"),g=require("primereact/iconbase");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function y(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var w=y(e),O=h(t);function I(){return I=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},I.apply(null,arguments)}function E(e){return E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},E(e)}function x(e,t){if("object"!=E(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=E(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function S(e){var t=x(e,"string");return"symbol"==E(t)?t:t+""}function D(e,t,n){return(t=S(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function j(e){if(Array.isArray(e))return e}function F(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,l,i,a=[],c=!0,u=!1;try{if(l=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=l.call(n)).done)&&(a.push(r.value),a.length!==t);c=!0);}catch(e){u=!0,o=e}finally{try{if(!c&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw o}}return a}}function N(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function k(e,t){if(e){if("string"==typeof e)return N(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?N(e,t):void 0}}function C(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function L(e,t){return j(e)||F(e,t)||k(e,t)||C()}function P(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function U(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?P(Object(n),!0).forEach((function(t){D(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):P(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var T=n.ComponentBase.extend({defaultProps:{__TYPE:"Dropdown",__parentMetadata:null,appendTo:null,ariaLabel:null,ariaLabelledBy:null,autoFocus:!1,autoOptionFocus:!1,checkmark:!1,children:void 0,className:null,clearIcon:null,collapseIcon:null,dataKey:null,disabled:!1,dropdownIcon:null,editable:!1,emptyFilterMessage:null,emptyMessage:null,filter:!1,filterBy:null,filterClearIcon:null,filterDelay:300,filterIcon:null,filterInputAutoFocus:!1,filterLocale:void 0,filterMatchMode:"contains",filterPlaceholder:null,filterTemplate:null,focusInputRef:null,focusOnHover:!0,highlightOnSelect:!0,id:null,inputId:null,inputRef:null,invalid:!1,itemTemplate:null,loading:!1,loadingIcon:null,maxLength:null,name:null,onBlur:null,onChange:null,onContextMenu:null,onFilter:null,onFocus:null,onHide:null,onMouseDown:null,onShow:null,optionDisabled:null,optionGroupChildren:"items",optionGroupLabel:null,optionGroupTemplate:null,optionLabel:null,options:null,optionValue:null,panelClassName:null,panelFooterTemplate:null,panelStyle:null,placeholder:null,required:!1,resetFilterOnHide:!1,scrollHeight:"200px",selectOnFocus:!1,showClear:!1,showFilterClear:!1,showOnFocus:!1,style:null,tabIndex:null,tooltip:null,tooltipOptions:null,transitionOptions:null,useOptionAsValue:!1,value:null,valueTemplate:null,variant:null,virtualScrollerOptions:null},css:{classes:{root:function(e){var t=e.props,n=e.focusedState,r=e.overlayVisibleState,o=e.context;return s.classNames("p-dropdown p-component p-inputwrapper",{"p-disabled":t.disabled,"p-invalid":t.invalid,"p-focus":n,"p-variant-filled":t.variant?"filled"===t.variant:o&&"filled"===o.inputStyle,"p-dropdown-clearable":t.showClear&&!t.disabled,"p-inputwrapper-filled":s.ObjectUtils.isNotEmpty(t.value),"p-inputwrapper-focus":n||r})},input:function(e){var t=e.props,n=e.label;return t.editable?"p-dropdown-label p-inputtext":s.classNames("p-dropdown-label p-inputtext",{"p-placeholder":null===n&&t.placeholder,"p-dropdown-label-empty":null===n&&!t.placeholder})},trigger:"p-dropdown-trigger",emptyMessage:"p-dropdown-empty-message",itemGroup:function(e){var t=e.optionGroupLabel;return s.classNames("p-dropdown-item-group",{"p-dropdown-item-empty":!t||0===t.length})},itemGroupLabel:"p-dropdown-item-group-label",dropdownIcon:"p-dropdown-trigger-icon p-clickable",loadingIcon:"p-dropdown-trigger-icon p-clickable",clearIcon:"p-dropdown-clear-icon p-clickable",filterIcon:"p-dropdown-filter-icon",filterClearIcon:"p-dropdown-filter-clear-icon",filterContainer:function(e){return s.classNames("p-dropdown-filter-container",{"p-dropdown-clearable-filter":!!e.clearIcon})},filterInput:function(e){var t=e.props,n=e.context;return s.classNames("p-dropdown-filter p-inputtext p-component",{"p-variant-filled":t.variant?"filled"===t.variant:n&&"filled"===n.inputStyle})},list:function(e){return"p-dropdown-items"},panel:function(e){var t=e.context;return s.classNames("p-dropdown-panel p-component",{"p-input-filled":t&&"filled"===t.inputStyle||"filled"===O.default.inputStyle,"p-ripple-disabled":t&&!1===t.ripple||!1===O.default.ripple})},item:function(e){var t=e.label;return s.classNames("p-dropdown-item",{"p-highlight":e.selected&&e.highlightOnSelect,"p-disabled":e.disabled,"p-focus":e.index===e.focusedOptionIndex,"p-dropdown-item-empty":!t||0===t.length})},itemLabel:"p-dropdown-item-label",checkIcon:"p-dropdown-check-icon",blankIcon:"p-dropdown-blank-icon",wrapper:"p-dropdown-items-wrapper",header:"p-dropdown-header",footer:"p-dropdown-footer",transition:"p-connected-overlay"},styles:"\n@layer primereact {\n .p-dropdown {\n display: inline-flex;\n cursor: pointer;\n position: relative;\n user-select: none;\n }\n \n .p-dropdown-trigger {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n }\n \n .p-dropdown-label {\n display: block;\n white-space: nowrap;\n overflow: hidden;\n flex: 1 1 auto;\n width: 1%;\n text-overflow: ellipsis;\n cursor: pointer;\n }\n \n .p-dropdown-label-empty {\n overflow: hidden;\n visibility: hidden;\n }\n \n input.p-dropdown-label {\n cursor: default;\n }\n \n .p-dropdown .p-dropdown-panel {\n min-width: 100%;\n }\n \n .p-dropdown-panel {\n position: absolute;\n top: 0;\n left: 0;\n }\n \n .p-dropdown-items-wrapper {\n overflow: auto;\n }\n \n .p-dropdown-item {\n cursor: pointer;\n font-weight: normal;\n white-space: nowrap;\n position: relative;\n overflow: hidden;\n }\n \n .p-dropdown-items {\n margin: 0;\n padding: 0;\n list-style-type: none;\n }\n \n .p-dropdown-filter {\n width: 100%;\n }\n \n .p-dropdown-filter-container {\n position: relative;\n }\n \n .p-dropdown-clear-icon,\n .p-dropdown-filter-icon,\n .p-dropdown-filter-clear-icon {\n position: absolute;\n top: 50%;\n margin-top: -.5rem;\n right: 2rem;\n }\n \n .p-fluid .p-dropdown {\n display: flex;\n }\n \n .p-fluid .p-dropdown .p-dropdown-label {\n width: 1%;\n }\n}\n",inlineStyles:{wrapper:function(e){return{maxHeight:e.props.scrollHeight||"auto"}},panel:function(e){return U({},e.props.panelStyle)}}}}),R=w.memo(w.forwardRef((function(e,t){var n=g.IconBase.getPTI(e);return w.createElement("svg",I({ref:t,width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg"},n),w.createElement("rect",{width:"1",height:"1",fill:"currentColor",fillOpacity:"0"}))})));R.displayName="BlankIcon";var M=w.memo((function(e){var t=r.useMergeProps(),n=e.ptm,o=e.cx,l=e.selected,i=e.disabled,a=e.option,c=e.label,u=e.index,p=e.focusedOptionIndex,d=e.ariaSetSize,f=e.checkmark,m=e.highlightOnSelect,g=e.onInputKeyDown,h=function(e){return n(e,{context:{selected:l,disabled:i,focused:u===p}})},y=e.template?s.ObjectUtils.getJSXElement(e.template,e.option):e.label,O=t({id:"dropdownItem_".concat(u),role:"option",className:s.classNames(a.className,o("item",{selected:l,disabled:i,label:c,index:u,focusedOptionIndex:p,highlightOnSelect:m})),style:e.style,tabIndex:0,onClick:function(t){return n=t,void(e.onClick&&e.onClick({originalEvent:n,option:a}));var n},onKeyDown:function(e){return g(e)},onMouseMove:function(t){return null==e?void 0:e.onMouseMove(t,u)},"aria-setsize":d,"aria-posinset":u+1,"aria-label":c,"aria-selected":l,"data-p-highlight":l,"data-p-focused":p===u,"data-p-disabled":i},h("item")),E=t({className:o("itemLabel")},h("itemLabel"));return w.createElement("li",I({key:e.label},O),f&&function(){if(l){var e=t({className:o("checkIcon")},h("checkIcon"));return w.createElement(v.CheckIcon,e)}var n=t({className:o("blankIcon")},h("blankIcon"));return w.createElement(R,n)}(),w.createElement("span",E,y),w.createElement(b.Ripple,null))}));function H(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?H(Object(n),!0).forEach((function(t){D(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):H(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}M.displayName="DropdownItem";var G=w.memo(w.forwardRef((function(e,n){var o,l,i,c,u,b=r.useMergeProps(),v=e.ptm,g=e.cx,h=e.sx,y=w.useContext(t.PrimeReactContext),O=w.useRef(null),E=!(e.visibleOptions&&e.visibleOptions.length)&&e.hasFilter,x=e.visibleOptions?e.visibleOptions.length:0,S={filter:function(e){return N(e)},reset:function(){return e.resetFilter()}},D=function(t,n){return v(t,A({hostName:e.hostName},n))},j=function(){e.onEnter((function(){if(e.virtualScrollerRef.current){var t=e.getSelectedOptionIndex();-1!==t&&setTimeout((function(){return e.virtualScrollerRef.current.scrollToIndex(t)}),0)}}))},F=function(){e.onEntered((function(){e.filter&&e.filterInputAutoFocus&&s.DomHandler.focus(O.current,!1)}))},N=function(t){e.onFilterInputChange&&e.onFilterInputChange(t)},k=function(){if(e.panelFooterTemplate){var t=s.ObjectUtils.getJSXElement(e.panelFooterTemplate,e,e.onOverlayHide),n=b({className:g("footer")},D("footer"));return w.createElement("div",n,t)}return null},C=function(t,n){var r;e.focusOnHover&&(null==e||null===(r=e.changeFocusedOptionIndex)||void 0===r||r.call(e,t,n))},L=function(n,r){var o=s.ObjectUtils.getJSXElement(n,e)||t.localeOption(r?"emptyFilterMessage":"emptyMessage"),l=b({className:g("emptyMessage")},D("emptyMessage"));return w.createElement("li",l,o)},P=function(t,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o={height:r.props?r.props.itemSize:void 0};if(o=A(A({},o),t.style),t.group&&e.optionGroupLabel){var l=e.optionGroupLabel,i=e.optionGroupTemplate?s.ObjectUtils.getJSXElement(e.optionGroupTemplate,t,n):e.getOptionGroupLabel(t),a=n+"_"+e.getOptionGroupRenderKey(t),c=b({className:g("itemGroup",{optionGroupLabel:l}),style:o,"data-p-highlight":e.selected},D("itemGroup")),u=b({className:g("itemGroupLabel")},D("itemGroupLabel"));return w.createElement("li",I({key:a},c),w.createElement("span",u,i))}var p=e.getOptionRenderKey(t)+"_"+n,d=e.getOptionLabel(t),f=e.isOptionDisabled(t);return w.createElement(M,{key:p,label:d,index:n,focusedOptionIndex:e.focusedOptionIndex,option:t,ariaSetSize:x,onInputKeyDown:e.onInputKeyDown,style:o,template:e.itemTemplate,selected:e.isSelected(t),highlightOnSelect:e.highlightOnSelect,disabled:f,onClick:e.onOptionClick,onMouseMove:C,ptm:v,cx:g,checkmark:e.checkmark})},U=function(){if(e.showFilterClear&&e.filterValue){var n=t.localeOption("clear"),r=b({className:g("filterClearIcon"),"aria-label":n,onClick:function(){return e.onFilterClearIconClick((function(){return s.DomHandler.focus(O.current)}))}},D("filterClearIcon"));return s.IconUtils.getJSXIcon(e.filterClearIcon||w.createElement(a.TimesIcon,r),A({},r),{props:e})}return null},T=function(){if(e.filter){var t=U(),n=b({className:g("filterIcon")},D("filterIcon")),r=s.IconUtils.getJSXIcon(e.filterIcon||w.createElement(d.SearchIcon,n),A({},n),{props:e}),o=b({className:g("filterContainer",{clearIcon:t})},D("filterContainer")),l=b({ref:O,type:"text",autoComplete:"off",className:g("filterInput",{context:y}),placeholder:e.filterPlaceholder,onKeyDown:e.onFilterInputKeyDown,onChange:function(e){return N(e)},value:e.filterValue},D("filterInput")),i=w.createElement("div",o,w.createElement("input",l),t,r);if(e.filterTemplate){var a={className:s.classNames("p-dropdown-filter-container",{"p-dropdown-clearable-filter":!!t}),element:i,filterOptions:S,filterInputKeyDown:e.onFilterInputKeyDown,filterInputChange:N,filterIconClassName:"p-dropdown-filter-icon",clearIcon:t,props:e};i=s.ObjectUtils.getJSXElement(e.filterTemplate,a)}var c=b({className:g("header")},D("header"));return w.createElement("div",c,i)}return null},R=function(){if(e.virtualScrollerOptions){var n=A(A({},e.virtualScrollerOptions),{style:A(A({},e.virtualScrollerOptions.style),{height:e.scrollHeight}),className:s.classNames("p-dropdown-items-wrapper",e.virtualScrollerOptions.className),items:e.visibleOptions,autoSize:!0,onLazyLoad:function(t){return e.virtualScrollerOptions.onLazyLoad(A(A({},t),{filter:e.filterValue}))},itemTemplate:function(e,t){return e&&P(e,t.index,t)},contentTemplate:function(n){var r=E?L(e.hasFilter?e.emptyFilterMessage:e.emptyMessage):n.children,o=b({ref:n.contentRef,style:n.style,className:s.classNames(n.className,g("list",{virtualScrollerProps:e.virtualScrollerOptions})),role:"listbox","aria-label":t.ariaLabel("listLabel")},D("list"));return w.createElement("ul",o,r)}});return w.createElement(m.VirtualScroller,I({ref:e.virtualScrollerRef},n,{pt:v("virtualScroller")}))}var r=s.ObjectUtils.isNotEmpty(e.visibleOptions)?e.visibleOptions.map(P):e.hasFilter?L(e.emptyFilterMessage,!0):L(e.emptyMessage),o=b({className:g("wrapper"),style:h("wrapper")},D("wrapper")),l=b({className:g("list"),role:"listbox","aria-label":t.ariaLabel("listLabel")},D("list"));return w.createElement("div",o,w.createElement("ul",l,r))},H=(o=T(),l=R(),i=k(),c=b({className:s.classNames(e.panelClassName,g("panel",{context:y})),style:h("panel"),onClick:e.onClick},D("panel")),u=b({classNames:g("transition"),in:e.in,timeout:{enter:120,exit:100},options:e.transitionOptions,unmountOnExit:!0,onEnter:j,onEntered:F,onExit:e.onExit,onExited:e.onExited},D("transition")),w.createElement(p.CSSTransition,I({nodeRef:n},u),w.createElement("div",I({ref:n},c),e.firstFocusableElement,o,l,i,e.lastFocusableElement)));return w.createElement(f.Portal,{element:H,appendTo:e.appendTo})})));function K(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=q(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l,i=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){a=!0,l=e},f:function(){try{i||null==n.return||n.return()}finally{if(a)throw l}}}}function q(e,t){if(e){if("string"==typeof e)return V(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?V(e,t):void 0}}function V(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function _(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function B(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?_(Object(n),!0).forEach((function(t){D(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):_(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}G.displayName="DropdownPanel";var z=w.memo(w.forwardRef((function(e,p){var d=r.useMergeProps(),f=w.useContext(t.PrimeReactContext),m=T.getProps(e,f),b=L(r.useDebounce("",m.filterDelay||0),3),v=b[0],g=b[1],h=b[2],y=L(w.useState(!1),2),x=y[0],S=y[1],j=L(w.useState(-1),2),F=j[0],N=j[1],k=L(w.useState(!1),2),C=k[0],P=k[1],U=w.useRef(!1),R=w.useRef(null),M=w.useRef(null),H=w.useRef(null),A=w.useRef(null),q=w.useRef(m.inputRef),V=w.useRef(m.focusInputRef),_=w.useRef(null),z=w.useRef(null),J=w.useRef(null),X=m.virtualScrollerOptions&&m.virtualScrollerOptions.lazy,Z=s.ObjectUtils.isNotEmpty(g),W=m.appendTo||f&&f.appendTo||O.default.appendTo,$=T.setMetaData(B(B({props:m},m.__parentMetadata),{},{state:{filter:g,focused:x,overlayVisible:C}})),Y=$.ptm,Q=$.cx,ee=$.sx;n.useHandleStyle(T.css.styles,$.isUnstyled,{name:"dropdown"});var te=L(r.useOverlayListener({target:R,overlay:M,listener:function(e,t){t.valid&&("outside"===t.type?le(e)||_e():f.hideOverlaysOnDocumentScrolling?_e():s.DomHandler.isDocument(e.target)||Be())},when:C}),2),ne=te[0],re=te[1],oe=function(e){return(e||[]).reduce((function(e,t,n){e.push(B(B({},t),{},{group:!0,index:n}));var r=Ye(t);return r&&r.forEach((function(t){return e.push(t)})),e}),[])},le=function(e){return s.DomHandler.isAttributeEquals(e.target,"data-pc-section","clearicon")||s.DomHandler.isAttributeEquals(e.target.parentElement||e.target,"data-pc-section","filterclearicon")},ie=function(e){m.showOnFocus&&!C&&Ve(),S(!0),m.onFocus&&m.onFocus(e)},ae=function(e){S(!1),m.onBlur&&setTimeout((function(){var t=q.current?q.current.value:void 0;m.onBlur({originalEvent:e.originalEvent,value:t,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:m.name,id:m.id,value:t}})}),200)},ce=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];He({originalEvent:e,option:t}),n&&(_e(),s.DomHandler.focus(V.current))},ue=function(e){if(m.disabled)e.preventDefault();else{switch(s.DomHandler.isAndroid()?e.key:e.code){case"ArrowDown":Oe(e);break;case"ArrowUp":Ie(e);break;case"ArrowLeft":case"ArrowRight":Ee(e,m.editable);break;case"Home":xe(e);break;case"End":Se(e);break;case"PageDown":je(e);break;case"PageUp":De(e);break;case"Space":Fe(e,m.editable);break;case"NumpadEnter":case"Enter":Ne(e);break;case"Escape":ke(e);break;case"Tab":Ce(e);break;case"Backspace":Le(e,m.editable);break;case"ShiftLeft":case"ShiftRight":break;default:!(e.metaKey||e.ctrlKey||e.altKey)&&s.ObjectUtils.isPrintableCharacter(e.key)&&(!C&&!m.editable&&Ve(),!m.editable&&ve(e,e.key))}U.current=!1}},se=function(e){var t;return pe(e)&&(null===(t=Xe(e))||void 0===t?void 0:t.toLocaleLowerCase(m.filterLocale).startsWith(J.current.toLocaleLowerCase(m.filterLocale)))},pe=function(e){return s.ObjectUtils.isNotEmpty(e)&&!($e(e)||We(e))},de=function(){return s.ObjectUtils.isNotEmpty(m.value)},fe=function(e){return pe(e)&&qe(e)},me=function(){return de?it.findIndex((function(e){return fe(e)})):-1},be=function(){var e=me();return e<0?ge():e},ve=function(e,t){J.current=(J.current||"")+t;var n=-1,r=!1;return s.ObjectUtils.isNotEmpty(J.current)&&(-1!==(n=-1!==F?-1===(n=it.slice(F).findIndex((function(e){return se(e)})))?it.slice(0,F).findIndex((function(e){return se(e)})):n+F:it.findIndex((function(e){return se(e)})))&&(r=!0),-1===n&&-1===F&&(n=be()),-1!==n&&ye(e,n)),z.current&&clearTimeout(z.current),z.current=setTimeout((function(){J.current="",z.current=null}),500),r},ge=function(){return it.findIndex((function(e){return pe(e)}))},he=function(){return s.ObjectUtils.findLastIndex(it,(function(e){return pe(e)}))},ye=function(e,t){F!==t&&(N(t),we(t),m.selectOnFocus&&ce(e,it[t],!1))},we=function(e){var t=s.DomHandler.findSingle(M.current,'li[id="dropdownItem_'.concat(e,'"]'));t&&t.focus()},Oe=function(e){if(C){var t=-1!==F?(r=(n=F)<it.length-1?it.slice(n+1).findIndex((function(e){return pe(e)})):-1)>-1?r+n+1:n:U.current?ge():be();ye(e,t)}else Ve(),m.editable&&ye(e,me());var n,r;e.preventDefault()},Ie=function(e){var t,n,r;if(e.altKey&&!(arguments.length>1&&void 0!==arguments[1]&&arguments[1]))-1!==F&&ce(e,it[F]),state.overlayVisible&&_e(),e.preventDefault();else{var o=-1!==F?(r=(n=F)>0?s.ObjectUtils.findLastIndex(it.slice(0,n),(function(e){return pe(e)})):-1)>-1?r:n:U.current?he():(t=me())<0?he():t;ye(e,o),!C&&Ve(),e.preventDefault()}},Ee=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&N(-1)},xe=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?(e.currentTarget.setSelectionRange(0,0),N(-1)):(ye(e,ge()),!C&&Ve()),e.preventDefault()},Se=function(e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1]){var t=e.currentTarget,n=t.value.length;t.setSelectionRange(n,n),N(-1)}else ye(e,he()),!C&&Ve();e.preventDefault()},De=function(e){e.preventDefault()},je=function(e){e.preventDefault()},Fe=function(e){!(arguments.length>1&&void 0!==arguments[1]&&arguments[1])&&Ne(e)},Ne=function(e){C?-1!==F&&ce(e,it[F]):(N(-1),Oe(e)),e.preventDefault()},ke=function(e){C&&_e(),e.preventDefault()},Ce=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]||(!C||s.DomHandler.getFocusableElements(M.current,':not([data-p-hidden-focusable="true"])').length>0?(-1!==F&&ce(e,it[F]),C&&_e()):(s.DomHandler.focus(H.current),e.preventDefault()))},Le=function(e){e&&(arguments.length>1&&void 0!==arguments[1]&&arguments[1])&&!C&&Ve()},Pe=function(e,t){if(!t||null==e||!e.length)return-1;var n=t.toLocaleLowerCase(),r=e.findIndex((function(e){return Xe(e).toLocaleLowerCase()===n}));return-1!==r?r:e.findIndex((function(e){return Xe(e).toLocaleLowerCase().startsWith(n)}))},Ue=function(e){!C&&Ve();var t=null;e.target.value&&it&&(t=Pe(it,e.target.value)),N(t),m.onChange&&m.onChange({originalEvent:e.originalEvent,value:e.target.value,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:m.name,id:m.id,value:e.target.value}})},Te=function(e){S(!0),_e(),m.onFocus&&m.onFocus(e)},Re=function(e){h(""),m.onFilter&&m.onFilter({filter:""}),e&&e()},Me=function(e){m.onChange&&m.onChange({originalEvent:e,value:void 0,stopPropagation:function(){null==e||e.stopPropagation()},preventDefault:function(){null==e||e.preventDefault()},target:{name:m.name,id:m.id,value:void 0}}),m.filter&&Re(),Je(),N(-1)},He=function(e){if(at!==e.option){Je(e.option),N(-1);var t=Ze(e.option),n=Ke(e.option,it);m.onChange&&m.onChange({originalEvent:e.originalEvent,value:t,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:m.name,id:m.id,value:t}}),ye(e.originalEvent,n)}},Ae=function(e){if(e=e||it){if(!m.optionGroupLabel)return Ke(m.value,e);for(var t=0;t<e.length;t++){var n=Ke(m.value,Ye(e[t]));if(-1!==n)return{group:t,option:n}}}return-1},Ge=function(){return m.optionValue?null:m.dataKey},Ke=function(e,t){var n=Ge();return t.findIndex((function(t){return s.ObjectUtils.equals(e,Ze(t),n)}))},qe=function(e){return s.ObjectUtils.equals(m.value,Ze(e),Ge())},Ve=function(){N(-1!==F?F:m.autoOptionFocus?be():m.editable?-1:me()),P(!0)},_e=function(){P(!1),U.current=!1},Be=function(){s.DomHandler.alignOverlay(M.current,q.current.parentElement,m.appendTo||f&&f.appendTo||O.default.appendTo)},ze=function(){var e=s.DomHandler.findSingle(M.current,'li[data-p-focused="true"]');if(e&&e.scrollIntoView)e.scrollIntoView({block:"nearest",inline:"nearest"});else{var t=s.DomHandler.findSingle(M.current,'li[data-p-highlight="true"]');t&&t.scrollIntoView&&t.scrollIntoView({block:"nearest",inline:"nearest"})}},Je=function(e){q.current&&(q.current.value=e?Xe(e):m.value||"",V.current&&(V.current.value=q.current.value))},Xe=function(e){if(s.ObjectUtils.isScalar(e))return"".concat(e);var t=m.optionLabel?s.ObjectUtils.resolveFieldData(e,m.optionLabel):e.label;return"".concat(t)},Ze=function(e){if(m.useOptionAsValue)return e;var t=m.optionValue?s.ObjectUtils.resolveFieldData(e,m.optionValue):e?e.value:s.ObjectUtils.resolveFieldData(e,"value");return m.optionValue||s.ObjectUtils.isNotEmpty(t)?t:e},We=function(e){return m.optionGroupLabel&&e.group},$e=function(e){return m.optionDisabled?s.ObjectUtils.isFunction(m.optionDisabled)?m.optionDisabled(e):s.ObjectUtils.resolveFieldData(e,m.optionDisabled):!(!e||void 0===e.disabled)&&e.disabled},Ye=function(e){return s.ObjectUtils.resolveFieldData(e,m.optionGroupChildren)},Qe=function(){if(m.editable&&q.current){var e=(at?Xe(at):null)||m.value||"";q.current.value=e,V.current&&(V.current.value=e)}};w.useImperativeHandle(p,(function(){return{props:m,show:Ve,hide:_e,clear:Me,focus:function(){return s.DomHandler.focus(V.current)},getElement:function(){return R.current},getOverlay:function(){return M.current},getInput:function(){return q.current},getFocusInput:function(){return V.current},getVirtualScroller:function(){return _.current}}})),w.useEffect((function(){s.ObjectUtils.combinedRefs(q,m.inputRef),s.ObjectUtils.combinedRefs(V,m.focusInputRef)}),[q,m.inputRef,V,m.focusInputRef]),r.useMountEffect((function(){m.autoFocus&&s.DomHandler.focus(V.current,m.autoFocus),Be()})),r.useUpdateEffect((function(){C&&(m.value||F>=0)&&ze()}),[C,m.value,F]),r.useUpdateEffect((function(){C&&g&&m.filter&&Be()}),[C,g,m.filter]),r.useUpdateEffect((function(){_.current&&_.current.scrollInView(0)}),[g]),r.useUpdateEffect((function(){Qe(),q.current&&(q.current.selectedIndex=1)})),r.useUnmountEffect((function(){s.ZIndexUtils.clear(M.current)}));var et,tt,nt,rt,ot,lt=function(e){"Enter"!==e.key&&"Space"!==e.code||(Me(e),e.preventDefault())},it=function(){var e=m.optionGroupLabel?oe(m.options):m.options;if(Z&&!X){var n=g.trim().toLocaleLowerCase(m.filterLocale),r=m.filterBy?m.filterBy.split(","):[m.optionLabel||"label"];if(m.optionGroupLabel){var o,l=[],i=K(m.options);try{for(i.s();!(o=i.n()).done;){var a=o.value,c=t.FilterService.filter(Ye(a),r,n,m.filterMatchMode,m.filterLocale);c&&c.length&&l.push(B(B({},a),D({},"".concat(m.optionGroupChildren),c)))}}catch(e){i.e(e)}finally{i.f()}return oe(l)}return t.FilterService.filter(e,r,n,m.filterMatchMode,m.filterLocale)}return e}(),at=-1!==(et=Ae(m.options))?m.optionGroupLabel?Ye(m.options[et.group])[et.option]:m.options[et]:null,ct=s.ObjectUtils.isNotEmpty(m.tooltip),ut=T.getOtherProps(m),st=s.ObjectUtils.reduceKeys(ut,s.DomHandler.ARIA_PROPS),pt=function(){var e={value:"",label:m.placeholder};if(at){var t=Ze(at);e={value:"object"===E(t)?m.options.findIndex((function(e){return e===t})):t,label:Xe(at)}}var n=d({className:"p-hidden-accessible p-dropdown-hidden-select"},Y("hiddenSelectedMessage")),r=d({ref:q,required:m.required,defaultValue:e.value,name:m.name,tabIndex:-1},Y("select")),o=d({value:e.value},Y("option"));return w.createElement("div",n,w.createElement("select",r,w.createElement("option",o,e.label)))}(),dt=function(){var e=s.ObjectUtils.isNotEmpty(at)?Xe(at):null;m.editable&&(e=e||m.value||"");var t=d({className:"p-hidden-accessible"},Y("hiddenSelectedMessage")),n=d(B({ref:V,id:m.inputId,defaultValue:e,type:"text",readOnly:!0,"aria-haspopup":"listbox",onFocus:ie,onBlur:ae,onKeyDown:ue,disabled:m.disabled,tabIndex:m.disabled?-1:m.tabIndex||0},st),Y("input"));return w.createElement("div",t,w.createElement("input",n))}(),ft=function(){var e=s.ObjectUtils.isNotEmpty(at)?Xe(at):null;if(m.editable){var t=d(B({ref:q,type:"text",defaultValue:e||m.value||"",className:Q("input",{label:e}),disabled:m.disabled,placeholder:m.placeholder,maxLength:m.maxLength,onInput:Ue,onFocus:Te,onKeyDown:ue,onBlur:ae,tabIndex:m.disabled?-1:m.tabIndex||0,"aria-haspopup":"listbox"},st),Y("input"));return w.createElement("input",t)}var n=m.valueTemplate?s.ObjectUtils.getJSXElement(m.valueTemplate,at,m):e||m.placeholder||m.emptyMessage||w.createElement(w.Fragment,null," "),r=d({ref:q,className:Q("input",{label:e}),tabIndex:"-1"},Y("input"));return w.createElement("span",r,n)}(),mt=m.loading?(tt=d({className:Q("loadingIcon"),"data-pr-overlay-visible":C},Y("loadingIcon")),nt=s.IconUtils.getJSXIcon(m.loadingIcon||w.createElement(i.SpinnerIcon,{spin:!0}),B({},tt),{props:m}),rt=m.placeholder||m.ariaLabel,ot=d({className:Q("trigger"),role:"button","aria-haspopup":"listbox","aria-expanded":C,"aria-label":rt},Y("trigger")),w.createElement("div",ot,nt)):function(){var e=d({className:Q("dropdownIcon"),"data-pr-overlay-visible":C},Y("dropdownIcon")),t=s.IconUtils.getJSXIcon(C?m.collapseIcon||w.createElement(l.ChevronUpIcon,e):m.dropdownIcon||w.createElement(o.ChevronDownIcon,e),B({},e),{props:m}),n=m.placeholder||m.ariaLabel,r=d({className:Q("trigger"),role:"button","aria-haspopup":"listbox","aria-expanded":C,"aria-label":n},Y("trigger"));return w.createElement("div",r,t)}(),bt=function(){if(null!=m.value&&m.showClear&&!m.disabled&&!s.ObjectUtils.isEmpty(m.options)){var e=d({className:Q("clearIcon"),onPointerUp:Me,tabIndex:m.editable?-1:m.tabIndex||"0",onKeyDown:lt,"aria-label":t.localeOption("clear")},Y("clearIcon"));return s.IconUtils.getJSXIcon(m.clearIcon||w.createElement(a.TimesIcon,e),B({},e),{props:m})}return null}(),vt=d({id:m.id,ref:R,className:s.classNames(m.className,Q("root",{context:f,focusedState:x,overlayVisibleState:C})),style:m.style,onClick:function(e){return t=e,void(m.disabled||m.loading||(m.onClick&&m.onClick(t),t.defaultPrevented||le(t)||"INPUT"===t.target.tagName||(M.current&&M.current&&M.current.contains(t.target)||(s.DomHandler.focus(V.current),C?_e():Ve()),t.preventDefault(),U.current=!0)));var t},onMouseDown:m.onMouseDown,onContextMenu:m.onContextMenu,onFocus:function(){m.editable&&!C&&!1===U.current&&s.DomHandler.focus(q.current)},"data-p-disabled":m.disabled,"data-p-focus":x,"aria-activedescendant":x?"dropdownItem_".concat(F):void 0},ut,Y("root")),gt=d({ref:H,role:"presentation",className:"p-hidden-accessible p-hidden-focusable",tabIndex:"0",onFocus:function(e){var t=e.relatedTarget===V.current?s.DomHandler.getFirstFocusableElement(M.current,':not([data-p-hidden-focusable="true"])'):V.current;s.DomHandler.focus(t)},"data-p-hidden-accessible":!0,"data-p-hidden-focusable":!0},Y("hiddenFirstFocusableEl")),ht=d({ref:A,role:"presentation",className:"p-hidden-accessible p-hidden-focusable",tabIndex:"0",onFocus:function(e){var t=e.relatedTarget===V.current?s.DomHandler.getLastFocusableElement(M.current,':not([data-p-hidden-focusable="true"])'):V.current;s.DomHandler.focus(t)},"data-p-hidden-accessible":!0,"data-p-hidden-focusable":!0},Y("hiddenLastFocusableEl"));return w.createElement(w.Fragment,null,w.createElement("div",vt,dt,pt,ft,bt,mt,w.createElement(G,I({hostName:"Dropdown",ref:M,visibleOptions:it,virtualScrollerRef:_},m,{appendTo:W,cx:Q,filterValue:v,focusedOptionIndex:F,getOptionGroupChildren:Ye,getOptionGroupLabel:function(e){return s.ObjectUtils.resolveFieldData(e,m.optionGroupLabel)},getOptionGroupRenderKey:function(e){return s.ObjectUtils.resolveFieldData(e,m.optionGroupLabel)},getOptionLabel:Xe,getOptionRenderKey:function(e){return m.dataKey?s.ObjectUtils.resolveFieldData(e,m.dataKey):Xe(e)},getSelectedOptionIndex:Ae,hasFilter:Z,in:C,isOptionDisabled:$e,isSelected:qe,onOverlayHide:_e,onClick:function(e){c.OverlayService.emit("overlay-click",{originalEvent:e,target:R.current})},onEnter:function(e){s.ZIndexUtils.set("overlay",M.current,f&&f.autoZIndex||O.default.autoZIndex,f&&f.zIndex.overlay||O.default.zIndex.overlay),s.DomHandler.addStyles(M.current,{position:"absolute",top:"0",left:"0"}),Be(),e&&e()},onEntered:function(e){e&&e(),ne(),m.onShow&&m.onShow()},onExit:function(){re()},onExited:function(){m.filter&&m.resetFilterOnHide&&Re(),s.ZIndexUtils.clear(M.current),m.onHide&&m.onHide()},onFilterClearIconClick:function(e){Re(e)},onFilterInputChange:function(e){var t=e.target.value;h(t),m.onFilter&&m.onFilter({originalEvent:e,filter:t})},onFilterInputKeyDown:function(e){switch(e.code){case"ArrowDown":Oe(e);break;case"ArrowUp":Ie(e);break;case"ArrowLeft":case"ArrowRight":Ee(e,!0);break;case"Enter":case"NumpadEnter":Ne(e),e.preventDefault();break;case"Escape":ke(e)}},onOptionClick:function(e){e.option.disabled||(He(e),s.DomHandler.focus(V.current)),_e()},onInputKeyDown:ue,ptm:Y,resetFilter:Re,changeFocusedOptionIndex:ye,firstFocusableElement:w.createElement("span",gt),lastFocusableElement:w.createElement("span",ht),sx:ee}))),ct&&w.createElement(u.Tooltip,I({target:R,content:m.tooltip,pt:Y("tooltip")},m.tooltipOptions)))})));z.displayName="Dropdown",exports.Dropdown=z;