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