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