react-autocomplete-plugin
Version:
A simple, powerful, lightweight and customizable autocomplete tool programmed for React projects!
2 lines (1 loc) • 28.4 kB
JavaScript
import{jsx as e,jsxs as t}from"react/jsx-runtime";import n,{useCallback as r,useRef as o,useState as l,useEffect as i}from"react";function a(e,t){if(e||t){var n=e||"",r=null==t?void 0:t.split(" ");if(!r)return n;for(var o=0,l=r;o<l.length;o++){n=n+" "+l[o]}return n}}var u=function(){return u=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},u.apply(this,arguments)};function d(t){var r=t.ariaInputLabel?t.ariaInputLabel:"Autocomplete input label",o=t.inputLabelStyle?t.inputLabelStyle:{},l=t.inputLabelClass?t.inputLabelClass:"",i=t.inputLabel?t.inputLabel:"Select or search item.";return e(n.Fragment,{children:e("label",u({"aria-label":r,className:a("label-value",l),htmlFor:"searchInput",style:o},{children:i}))})}var c=function(){return c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)};var s=n.forwardRef((function(r,o){var l=void 0===r.showdropDownArrow||null===r.showdropDownArrow||r.showdropDownArrow,i=void 0===r.showClearOption||null===r.showClearOption||r.showClearOption,u=r.placeHolder?r.placeHolder:"Type or select..";return t(n.Fragment,{children:[e("input",{onFocus:r.handleOnFocusEvent,onBlur:r.handleOnBlurEvent,onInput:r.onSearch,id:"searchInput",className:a("auto-complete-textfield",r.inputFieldClass),style:r.inputFieldStyle,ref:o,placeholder:u,type:"text",autoComplete:"off",disabled:!!r.isAutoCompleteDisabled,role:(null==r?void 0:r.ariaRole)?r.ariaRole:"textbox","aria-roledescription":(null==r?void 0:r.ariaRoleDescription)?r.ariaRoleDescription:"Autocomplete input field","aria-label":(null==r?void 0:r.ariaInputField)?r.ariaInputField:"Autocomplete input field"}),l&&e("span",{tabIndex:0,className:"arrow down",onClick:r.handleDropdownClick}),i&&e("span",c({className:"auto-complete-remove-selection",onClick:r.clearSearch},{children:"×"}))]})})),v=function(){return v=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},v.apply(this,arguments)};var p=n.forwardRef((function(t,o){var l=r((function(){var e={};return(null==t?void 0:t.dropdownListStyle)&&(e=v({},t.dropdownListStyle)),e}),[t.dropdownListStyle]),i=r((function(){var e="";return(null==t?void 0:t.dropdownListClass)&&(e=t.dropdownListClass),e&&""!==e?a("autocomplete-data-list",e):a("autocomplete-data-list")}),[t.dropdownListClass]);return e(n.Fragment,{children:e("li",v({tabIndex:0,ref:o,id:"autocomplete-li-element-"+t.index,className:"".concat(i()).concat(t.disableProperty&&t.data[t.disableProperty]||t.disableListFn&&t.disableListFn(t.index,t.data)?" disable-list-element":""),style:l(),onMouseDown:function(){return t.onSelect(t.index,t.data,!0)},"aria-disabled":!!(t.disableProperty&&t.data[t.disableProperty]||t.disableListFn&&t.disableListFn(t.index,t.data)),"aria-label":t.objectProperty?t.data[t.objectProperty]:t.data},{children:t.objectProperty?t.data[t.objectProperty]:t.data}),t.index)})})),f=function(){return f=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},f.apply(this,arguments)},h=function(e,t,n,r){return new(n||(n=Promise))((function(o,l){function i(e){try{u(r.next(e))}catch(e){l(e)}}function a(e){try{u(r.throw(e))}catch(e){l(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}u((r=r.apply(e,t||[])).next())}))},m=function(e,t){var n,r,o,l,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return l={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},w=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,l=t.length;o<l;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};function g(u){var d,c,v,g,b,y,L,C,S,x,D,F,k,E,V,A,T,O,R,M=this,I=o(null),P=o(0),j=u.scrollThreshold?u.scrollThreshold:3,N=l(!1),H=N[0],B=N[1],z=o(null),U=o([]),q=l(!1),W=q[0],G=q[1],Y=l([]),J=Y[0],K=Y[1],Q=l([]),X=Q[0],Z=Q[1],$=u.noSearchResultMessage?u.noSearchResultMessage:"No results found.",_=u.initialVisibleData?u.initialVisibleData:1e3,ee=void 0===u.isScrollThresholdRequired||null===u.isScrollThresholdRequired||u.isScrollThresholdRequired,te=l(!1),ne=te[0],re=te[1],oe=l(0),le=oe[0],ie=oe[1],ae=l(!1),ue=ae[0],de=ae[1],ce=l(!1),se=ce[0],ve=ce[1],pe=u.viewMoreText?u.viewMoreText:"View More",fe=void 0===u.showViewMore||null===u.showViewMore||u.showViewMore,he=void 0===u.showLoadingSpinner||null===u.showLoadingSpinner||u.showLoadingSpinner,me=void 0!==u.isApiLoad&&null!==u.isApiLoad&&u.isApiLoad,we=void 0!==u.disableProperty&&null!==u.disableProperty?u.disableProperty:void 0,ge=void 0!==u.objectProperty&&null!==u.objectProperty?u.objectProperty:void 0,be=void 0!==u.triggerApiLoadEvent&&null!==u.triggerApiLoadEvent&&"function"==typeof u.triggerApiLoadEvent?u.triggerApiLoadEvent:void 0,ye=void 0!==u.disableListFn&&null!==u.disableListFn&&"function"==typeof u.disableListFn?u.disableListFn:void 0,Le=void 0!==u.broadcastSelectedValue&&null!==u.broadcastSelectedValue&&"function"==typeof u.broadcastSelectedValue?u.broadcastSelectedValue:void 0,Ce=o(null),Se=o(null),xe=o(-1),De=o(!1),Fe=r((function(){var e,t,n=null===(e=Ce.current)||void 0===e?void 0:e.style,r=null===(t=I.current)||void 0===t?void 0:t.clientWidth;n&&r&&(n.width=r+"px")}),[]),ke=r((function(e,t,n){if(!n)return!1;null!=t&&(we&&t[we]||null!=ye&&ye(e,t)||(I.current.value=ge?t[ge]:t,B(!1),de(!1),K([]),Z([]),ve(!1),Pe(),Le&&Le(t)))}),[Le,ye,we,ge]),Ee=function(e){return h(M,void 0,void 0,(function(){var e,t,n,r,o,l,i,a;return m(this,(function(d){switch(d.label){case 0:return d.trys.push([0,3,,4]),(null===(l=I.current)||void 0===l?void 0:l.value)&&""!==(null===(i=I.current)||void 0===i?void 0:i.value.trim())?(ue||de(!0),P.current=0,H||B(!0),u.searchFn&&"function"==typeof u.searchFn?[4,u.searchFn(I.current.value,u.dropdownData)]:[3,2]):(Z([]),Ve(),Ae(),null===(a=z.current)||void 0===a||a.scrollTo(0,0),[2]);case 1:if((e=d.sent())&&e.length>0)return Z(e),r=e.slice(0,_),P.current=P.current+r.length,K(r),Ae(),[2];d.label=2;case 2:return ge?(t=u.dropdownData.filter((function(e){var t;return null===(t=e[ge])||void 0===t?void 0:t.toString().toLowerCase().includes(I.current.value.toLowerCase().trim())})),t.length>0?(r=t.slice(0,_),P.current=P.current+r.length,Z(t),K(r),Ae(),[2]):(K([]),[2])):(n=u.dropdownData.filter((function(e){return null==e?void 0:e.toString().toLowerCase().includes(I.current.value.toLowerCase().trim())}))).length>0?(r=n.slice(0,_),P.current=P.current+r.length,Z(n),K(r),Ae(),[2]):(K([]),[2]);case 3:return o=d.sent(),console.log(o),[3,4];case 4:return[2]}}))}))},Ve=function(){var e,t=ue&&X.length>0&&(null===(e=I.current)||void 0===e?void 0:e.value)?X.slice(0,_):u.dropdownData.slice(0,_);K(t),P.current=t.length},Ae=r((function(){var e;void 0!==u.totalRecords&&le>=u.totalRecords?ve(!1):(null===(e=I.current)||void 0===e?void 0:e.value)&&""!==I.current.value&&me&&!ne||P.current>=le?ve(!0):ve(!1)}),[le,u.totalRecords,ne,me]),Te=function(){try{if(!H)return;setTimeout((function(){Oe()}),50)}catch(e){console.log(e)}},Oe=function(){var e,t,n=X.length>0?w([],X,!0):w([],u.dropdownData,!0);if(u.dropdownData.length!==P.current&&X.length!==P.current){if(n.length>J.length){var r,o=Math.ceil(J.length/j);if(ee&&o>=_){var l=w([],J,!0);l.splice(0,_),(r=n.slice(P.current,P.current+_)).length>0&&(P.current=P.current+r.length,ue&&(null===(e=I.current)||void 0===e?void 0:e.value)&&""!==I.current.value&&(r=ge?r.filter((function(e){var t,n,r;return null===(t=e[ge])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=u.defaultValue)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())})):r.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=u.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),K(w(w([],l,!0),r,!0)))}else(r=n.slice(P.current,P.current+_)).length>0&&(P.current=P.current+r.length,ue&&(null===(t=I.current)||void 0===t?void 0:t.value)&&""!==I.current.value&&(r=ge?r.filter((function(e){var t,n,r;return null===(t=e[ge])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=I.current.value)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())})):r.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=I.current.value)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),K((function(e){return w(w([],e,!0),r,!0)})));setTimeout((function(){var e;null===(e=z.current)||void 0===e||e.scrollTo(0,Math.ceil(50*z.current.scrollHeight/100))}),75)}}else if(!ne&&me&&be&&"function"==typeof be){if(u.optViewMoreOnlyForApiCall)return ve(!0),void setTimeout((function(){var e;null===(e=z.current)||void 0===e||e.scrollTo(0,z.current.scrollHeight+10)}),75);be({dataIndex:u.dropdownData.length}),re(!0),he&&(G(!0),setTimeout((function(){var e;null===(e=z.current)||void 0===e||e.scrollTo(0,z.current.scrollHeight+10)}),75))}},Re=r((function(e,t,n){var r;try{var o=w([],e,!0);if(o.length<=_)return K(o),P.current=o.length,void Ae();var l=o.slice(0,_);return P.current=l.length,ue&&(null===(r=I.current)||void 0===r?void 0:r.value)&&""!==I.current.value&&(l=n?l.filter((function(e){var t,r,o;return null===(t=e[n])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(o=null===(r=I.current.value)||void 0===r?void 0:r.toString())||void 0===o?void 0:o.toLowerCase().trim())})):l.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=I.current.value)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),K(l),void Ae()}catch(e){console.log(e)}}),[_,ue,Ae]),Me=r((function(e){var t,n,r;try{if(!ne)return;if((null===(t=I.current)||void 0===t?void 0:t.value)&&""!==I.current.value){var o=void 0;if(o=ge?e.filter((function(e){var t;return null===(t=e[ge])||void 0===t?void 0:t.toString().toLowerCase().includes(I.current.value.toLowerCase().trim())})):e.filter((function(e){return null==e?void 0:e.toString().toLowerCase().includes(I.current.value.toLowerCase().trim())})),o&&o.length>0){ue&&Z(o);var l=o.slice(P.current,P.current+_);if(l&&l.length>0){P.current=P.current+l.length;var i=Math.ceil(J.length/j);if(ee&&i>=_)(d=w([],J,!0)).splice(0,_),K(w(w([],d,!0),l,!0));else K((function(e){return w(w([],e,!0),l,!0)}))}setTimeout((function(){var e;null===(e=z.current)||void 0===e||e.scrollTo(0,Math.ceil(50*z.current.scrollHeight/100)),re(!1),G(!1)}),100)}else re(!1),G(!1),Z([]),K([]);return}if(e.length>J.length){var a,d;i=Math.ceil(J.length/j);if(ee&&i>=_)(d=w([],J,!0)).splice(0,_),(a=e.slice(P.current,P.current+_)).length>0&&(P.current=P.current+a.length,u.defaultValue&&(null===(n=I.current)||void 0===n?void 0:n.value)&&""!==I.current.value&&(a=ge?a.filter((function(e){var t,n,r;return null===(t=e[ge])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=u.defaultValue)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())})):a.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=u.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),K(w(w([],d,!0),a,!0)));else(a=e.slice(P.current,P.current+_)).length>0&&(P.current=P.current+a.length,u.defaultValue&&(null===(r=I.current)||void 0===r?void 0:r.value)&&""!==I.current.value&&(a=ge?a.filter((function(e){var t,n,r;return null===(t=e[ge])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=u.defaultValue)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())})):a.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=u.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),K((function(e){return w(w([],e,!0),a,!0)})));setTimeout((function(){var e;null===(e=z.current)||void 0===e||e.scrollTo(0,Math.ceil(50*z.current.scrollHeight/100)),re(!1),G(!1)}),100)}}catch(e){console.log(e)}}),[J,_,ee,j,ne,ge,u.defaultValue,ue]),Ie=r((function(e,t){var n;t&&me&&!ne&&"function"==typeof be&&(be({dataIndex:le}),null===(n=I.current)||void 0===n||n.focus(),re(!0),he&&G(!0))}),[me,ne,be,le,he]),Pe=function(){var e,t;-1!==xe.current&&(null===(e=U.current[xe.current])||void 0===e||e.classList.remove("autocomplete-keydown-background")),De.current&&(null===(t=Se.current)||void 0===t||t.classList.remove("autocomplete-keydown-viewmore")),xe.current=-1,De.current=!1,U.current=[]};return i((function(){var e,t;if(H){var n=null===(e=Ce.current)||void 0===e?void 0:e.style,r=null===(t=I.current)||void 0===t?void 0:t.clientWidth;(null==n?void 0:n.width)!==r+"px"&&Fe(),ne&&le!==u.dropdownData.length&&"function"==typeof be&&Me(u.dropdownData)}}),[le,ne,be,Me,u.dropdownData,H,Fe]),i((function(){H||Re(u.dropdownData,u.defaultValue,ge)}),[Re,u.dropdownData,u.defaultValue,ge,H]),i((function(){u.dropdownData.length>0&&ie(u.dropdownData.length)}),[u.dropdownData]),i((function(){var e=function(){Fe()};return H?window.addEventListener("resize",e):window.removeEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[Fe,H]),i((function(){var e=function(e){var t,n,r,o,l,i,a,u,d,c,s;if(!(J.length<=0&&27!==(null==e?void 0:e.keyCode)))switch(null==e?void 0:e.keyCode){case 27:return void(H&&(B(!1),null===(t=I.current)||void 0===t||t.blur(),Pe()));case 13:if(De.current)return Ie(null,!0),void(De.current=!1);if(null===(n=U.current[xe.current])||void 0===n?void 0:n.classList.contains("disable-list-element"))return;var v=J[xe.current];return null!=v&&(ke(xe.current,v,!0),null===(r=U.current[xe.current])||void 0===r||r.classList.remove("autocomplete-keydown-background")),void(null===(o=I.current)||void 0===o||o.blur());case 40:if(xe.current+1===U.current.length)return void(Se.current&&(null===(l=Se.current)||void 0===l||l.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(i=Se.current)||void 0===i||i.classList.add("autocomplete-keydown-viewmore"),null===(a=U.current[xe.current])||void 0===a||a.classList.remove("autocomplete-keydown-background"),De.current=!0));if(xe.current=xe.current+1,null==(s=null===(u=U.current[xe.current])||void 0===u?void 0:u.id))return;if(!s.includes("autocomplete-li-element-"))return;if("number"!=typeof Number(s.substring(s.lastIndexOf("-")+1)))return;return void setTimeout((function(){var e,t,n,r,o;null===(e=U.current[xe.current])||void 0===e||e.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(t=U.current[xe.current])||void 0===t||t.classList.add("autocomplete-keydown-background"),xe.current>0&&(null===(n=U.current[xe.current-1])||void 0===n||n.classList.remove("autocomplete-keydown-background"),xe.current+1===U.current.length&&se&&(null===(r=z.current)||void 0===r||r.scrollTo(0,(null===(o=z.current)||void 0===o?void 0:o.scrollHeight)+10)))}),20);case 38:if(xe.current<=0)return;if(De.current?(null===(d=Se.current)||void 0===d||d.classList.remove("autocomplete-keydown-viewmore"),De.current=!1):xe.current=xe.current-1,null==(s=null===(c=U.current[xe.current])||void 0===c?void 0:c.id))return;if(!s.includes("autocomplete-li-element-"))return;if("number"!=typeof Number(s.substring(s.lastIndexOf("-")+1)))return;return void setTimeout((function(){var e,t,n;null===(e=U.current[xe.current])||void 0===e||e.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(t=U.current[xe.current])||void 0===t||t.classList.add("autocomplete-keydown-background"),null===(n=U.current[xe.current+1])||void 0===n||n.classList.remove("autocomplete-keydown-background")}),20);default:return}};return H?window.addEventListener("keydown",e):window.removeEventListener("keydown",e),function(){return window.removeEventListener("keydown",e)}}),[J,se,ke,Ie,H]),i((function(){if(!(ne||le>0)&&u.defaultValue)if(ge){var e=void 0;(e="object"==typeof u.defaultValue?u.dropdownData.find((function(e){return e[ge]===u.defaultValue[ge]})):u.dropdownData.find((function(e){return e[ge]===u.defaultValue})))&&(I.current.value=e[ge])}else{e=void 0;(e="object"==typeof u.defaultValue?u.dropdownData.find((function(e){return e===u.defaultValue[ge]})):u.dropdownData.find((function(e){return e===u.defaultValue})))&&(I.current.value=e)}}),[u.dropdownData,u.defaultValue,ge,ne,le]),t(n.Fragment,{children:[e(s,{handleOnBlurEvent:function(e){var t,n,r,o,l,i,a,d,c;(null===(n=null===(t=null==e?void 0:e.relatedTarget)||void 0===t?void 0:t.classList)||void 0===n?void 0:n.contains("arrow"))||((null===(o=null===(r=null==e?void 0:e.relatedTarget)||void 0===r?void 0:r.classList)||void 0===o?void 0:o.contains("unorder-list"))?null===(l=I.current)||void 0===l||l.focus():(null===(a=null===(i=null==e?void 0:e.relatedTarget)||void 0===i?void 0:i.classList)||void 0===a?void 0:a.contains("disable-list-element"))||(null===(c=null===(d=null==e?void 0:e.relatedTarget)||void 0===d?void 0:d.classList)||void 0===c?void 0:c.contains("autocomplete-data-list"))||(u.inspectAutoCompleteList?console.warn("You have turned off blur event in autocomplete module which will not close autocomplete list. Hope you know what you are doing. Update to false after inspect is complete."):(B(!1),K([]),Pe(),u.triggerBlurEvent&&"function"==typeof u.triggerBlurEvent&&u.triggerBlurEvent(e))))},handleOnFocusEvent:function(e){var t,n,r;if(!u.isAutoCompleteDisabled){B(!0),Fe();var o=null===(t=Ce.current)||void 0===t?void 0:t.style,l=null===(n=I.current)||void 0===n?void 0:n.clientWidth;o&&l&&(o.width=l+"px"),u.triggerOnFocusEvent&&"function"==typeof u.triggerOnFocusEvent&&u.triggerOnFocusEvent(e),J.length<=0&&(ue&&(null===(r=I.current)||void 0===r?void 0:r.value)&&""!==I.current.value?Ee():Re(u.dropdownData,u.defaultValue,ge))}},onSearch:u.searchFn?u.searchFn:Ee,ariaInputField:null===(d=u.aria)||void 0===d?void 0:d.ariaInputField,ariaRole:null===(c=u.aria)||void 0===c?void 0:c.ariaRole,ariaRoleDescription:null===(v=u.aria)||void 0===v?void 0:v.ariaRoleDescription,inputFieldClass:null===(g=u.customClass)||void 0===g?void 0:g.inputFieldClass,inputFieldStyle:null===(b=u.customStyle)||void 0===b?void 0:b.inputFieldStyle,isAutoCompleteDisabled:u.isAutoCompleteDisabled,placeHolder:u.placeHolder,ref:I,clearSearch:function(e){u.isAutoCompleteDisabled||(I.current.value="",u.triggerClearSelectionEvent&&"function"==typeof u.triggerClearSelectionEvent&&u.triggerClearSelectionEvent(e))},handleDropdownClick:function(e){var t;u.isAutoCompleteDisabled||(H?B(!1):null===(t=I.current)||void 0===t||t.focus())},showClearOption:u.showClearOption,showdropDownArrow:u.showdropDownArrow},"input-field"),e("div",f({id:"autoCompleteListContainerId",ref:Ce,className:a("auto-complete-list",null===(y=null==u?void 0:u.customClass)||void 0===y?void 0:y.listContainerClass),style:(null===(L=null==u?void 0:u.customStyle)||void 0===L?void 0:L.listContainerStyle)?u.customStyle.listContainerStyle:{},"aria-label":(null===(C=u.aria)||void 0===C?void 0:C.ariaListContainer)?u.aria.ariaListContainer:"Autocomplete list container."},{children:H&&e("div",f({id:"list-container"},{children:t("ul",f({id:"list-id",ref:z,onScroll:function(e){var t,n;if(!(J.length<=0)){if(e.target.offsetHeight+e.target.scrollTop>=e.target.scrollHeight){if(u.totalRecords&&P.current>=u.totalRecords)return void ve(!1);Te()}else ee&&e.target.scrollTop<10&&J.length>_&&Ve();0===e.target.scrollTop&&(-1!==xe.current&&(null===(t=U.current[xe.current])||void 0===t||t.classList.remove("autocomplete-keydown-background")),De.current&&(null===(n=Se.current)||void 0===n||n.classList.remove("autocomplete-keydown-viewmore")),xe.current=-1,De.current=!1)}},className:a("unorder-list",null===(S=null==u?void 0:u.customClass)||void 0===S?void 0:S.dropdownUnorderedListClass),style:(null===(x=null==u?void 0:u.customStyle)||void 0===x?void 0:x.dropdownUnorderedListStyle)?u.customStyle.dropdownUnorderedListStyle:{},tabIndex:0,"aria-label":(null===(D=u.aria)||void 0===D?void 0:D.ariaULList)?u.aria.ariaULList:"Autocomplete unordered list"},{children:[J.length>0&&J.map((function(t,n){var r,o;return ge||"object"!=typeof t?e(p,{index:n,onSelect:ke,data:t,disableListFn:ye,disableProperty:we,dropdownListClass:null===(r=u.customClass)||void 0===r?void 0:r.dropdownListClass,dropdownListStyle:null===(o=u.customStyle)||void 0===o?void 0:o.dropdownListStyle,objectProperty:ge,ref:function(e){U.current[n]=e}},n):null})),W&&he&&!u.isCustomSpinner&&e("li",f({className:"auto-complete-list-spinner"},{children:e("span",{className:"autocomplete-plugin-loader"})})),W&&he&&u.isCustomSpinner&&e("li",f({className:"auto-complete-list-spinner"},{children:e("span",{className:(null===(F=null==u?void 0:u.customClass)||void 0===F?void 0:F.customSpinnerClass)?u.customClass.customSpinnerClass:"",style:(null===(k=null==u?void 0:u.customStyle)||void 0===k?void 0:k.customSpinnerStyle)?u.customStyle.customSpinnerStyle:{}})})),!W&&J.length<=0&&e("li",f({className:a("autocomplete-data-list noSearchResult",null===(E=null==u?void 0:u.customClass)||void 0===E?void 0:E.noResultClass),style:(null===(V=null==u?void 0:u.customStyle)||void 0===V?void 0:V.noResultStyle)?u.customStyle.noResultStyle:{},"aria-label":(null===(A=u.aria)||void 0===A?void 0:A.ariaNoSearchResult)?u.aria.ariaNoSearchResult:"No search result."},{children:$})),fe&&!ne&&!W&&me&&se&&e("li",f({className:a("autocomplete-data-list view-more",null===(T=null==u?void 0:u.customClass)||void 0===T?void 0:T.viewMoreClass),style:(null===(O=null==u?void 0:u.customStyle)||void 0===O?void 0:O.viewMoreStyle)?u.customStyle.viewMoreStyle:{},"aria-label":(null===(R=u.aria)||void 0===R?void 0:R.ariaViewMore)?u.aria.ariaViewMore:"View more results",tabIndex:0,onClick:function(e){return Ie(e,!0)},ref:Se},{children:pe}))]}))}))}))]})}!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("\n.auto-complete-textfield-container {\n width: 100%;\n height: inherit;\n }\n \n .auto-complete-remove-selection {\n display: inline-block;\n margin-top: 5px;\n margin-left: -25px;\n cursor: pointer;\n }\n \n .auto-complete-textfield {\n width: 100%;\n height: 2rem;\n outline: none;\n border: 1px solid grey;\n border-radius: 5px;\n cursor: text;\n }\n \n .auto-complete-list {\n position: absolute;\n background-color: #FFFFFF;\n }\n \n .field-container {\n width: inherit;\n }\n \n .unorder-list {\n list-style: none;\n max-height: 20rem;\n overflow: auto;\n margin: 0;\n padding: 0;\n text-align: center;\n border: 1px solid #E8E8E8;\n box-shadow: 0 2px 3px -1px rgba(0, 0, 0, 0.1);\n color: #000000;\n }\n \n .autocomplete-data-list {\n padding: 1rem;\n }\n \n .autocomplete-data-list:hover {\n background-color: #EEEDED;\n cursor: pointer;\n }\n \n .showDropdown {\n display: block;\n }\n \n .autocomplete-plugin-loader {\n width: 2rem;\n height: 2rem;\n border: 3px solid #D4D3D3;\n border-bottom-color: transparent;\n border-radius: 50%;\n display: inline-block;\n box-sizing: border-box;\n animation: rotation 1s linear infinite;\n position: relative;\n }\n \n .auto-complete-textfield:disabled {\n background-color: #E7E7E7;\n border: 1px solid #D5D5D5;\n cursor: default;\n }\n \n .auto-complete-list-spinner {\n padding: 1rem;\n }\n \n @keyframes rotation {\n 0% {\n transform: rotate(0deg);\n }\n \n 100% {\n transform: rotate(360deg);\n }\n }\n \n .arrow {\n height: 0;\n width: 0;\n border: 4px solid transparent;\n display: inline-block;\n margin-top: 5px;\n margin-left: -20px;\n cursor: pointer;\n }\n \n .arrow.down {\n border-top-color: #000;\n }\n \n .disable-list-element {\n pointer-events:none;\n opacity:0.5;\n background-color: #E5E5E5;\n }\n \n ::-webkit-input-placeholder {\n text-transform: capitalize;\n }\n \n ::-moz-placeholder {\n text-transform: capitalize;\n }\n \n ::-ms-placeholder {\n text-transform: capitalize;\n }\n \n .view-more {\n cursor: pointer;\n background-color: #f6f5f5;\n letter-spacing: 0.5px;\n }\n \n .autocomplete-keydown-background {\n background-color: #F4F4F4;\n }\n \n .autocomplete-keydown-viewmore {\n background-color: #c8c8c8;\n }");var b=function(){return b=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},b.apply(this,arguments)};function y(n){var r,l,i,a,u,c,s,v,p=o(null),f=n.customClass?n.customClass:{},h=n.customStyle?n.customStyle:{},m=n.inputLabel?n.inputLabel:"Select a value",w=function(e,t){if(e||t){var n=e||"",r=null==t?void 0:t.split(" ");if(!r)return n;for(var o=0,l=r;o<l.length;o++){n=n+" "+l[o]}return n}};return t("div",b({className:w("auto-complete-textfield-container",f.parentContainerClass),ref:p,style:h.parentContainerStyle?h.parentContainerStyle:{}},{children:[n.showInputlabel&&e("div",b({className:w("label-container",f.inputLabelContainerClass),style:h.inputLabelContainerStyle?h.inputLabelContainerStyle:{}},{children:e(d,{inputLabel:m,ariaInputLabel:null===(r=n.aria)||void 0===r?void 0:r.ariaInputLabel,inputLabelClass:null===(l=n.customClass)||void 0===l?void 0:l.inputLabelClass,inputLabelStyle:null===(i=n.customStyle)||void 0===i?void 0:i.inputLabelStyle},"label-key")})),e(g,{dropdownData:n.dropdownData,objectProperty:n.objectProperty,initialVisibleData:n.initialVisibleData,placeHolder:n.placeHolder,inputFieldClass:null===(a=n.customClass)||void 0===a?void 0:a.inputFieldClass,inputFieldStyle:null===(u=n.customStyle)||void 0===u?void 0:u.inputFieldStyle,isAutoCompleteDisabled:n.isAutoCompleteDisabled,ariaInputField:null===(c=n.aria)||void 0===c?void 0:c.ariaInputField,ariaRole:null===(s=n.aria)||void 0===s?void 0:s.ariaRole,ariaRoleDescription:null===(v=n.aria)||void 0===v?void 0:v.ariaRoleDescription,showClearOption:n.showClearOption,showdropDownArrow:n.showdropDownArrow,inspectAutoCompleteList:n.inspectAutoCompleteList,broadcastSelectedValue:n.broadcastSelectedValue,disableListFn:n.disableListFn,disableProperty:n.disableProperty,triggerClearSelectionEvent:n.triggerClearSelectionEvent,customStyle:n.customStyle,aria:n.aria,customClass:n.customClass,isCustomSpinner:n.isCustomSpinner,noSearchResultMessage:n.noSearchResultMessage,showLoadingSpinner:n.showLoadingSpinner,defaultValue:n.defaultValue,isScrollThresholdRequired:n.isScrollThresholdRequired,triggerBlurEvent:n.triggerBlurEvent,triggerApiLoadEvent:n.triggerApiLoadEvent,isApiLoad:n.isApiLoad,scrollThreshold:n.scrollThreshold,triggerOnFocusEvent:n.triggerOnFocusEvent,totalRecords:n.totalRecords,searchFn:n.searchFn,optViewMoreOnlyForApiCall:n.optViewMoreOnlyForApiCall,showViewMore:n.showViewMore,viewMoreText:n.viewMoreText},"input-field")]}))}export{y as Autocomplete};