import React, {useEffect, useState} from 'react'; const { __ } = wp.i18n; export function SearchDropdown( props ) { const [searchResultsFieldStatus, setSearchResultsFieldStatus] = useState( 'closed' ); const [textareaValue, setTextareaValue] = useState( '' ); const [dropdownMarkup, setDropdownMarkup] = useState( '' ); const [reset, setReset] = useState( false ); let searchResultsItems = []; /** * Sets the dropdown content when there's a change on any of props.searchResults, props.showDefaultMessage, props.showNoResultsMessage */ useEffect(() => { if ( props.searchResults ) { searchResultsItems = props.searchResults; } else { searchResultsItems = []; } if ( ! props.showDefaultMessage && ! props.showNoResultsMessage ) { setDropdownMarkup( printItems() ); } else { setDropdownMarkup( dropdownContent() ); } }, [props.searchResults, props.showDefaultMessage, props.showNoResultsMessage], reset); /** * Initially sets the dropdown content to the default message. */ useEffect( () => { setDropdownMarkup( getDefaultMessage() ); }, [] ); /** * On dropdown container focus, the textarea gets focused so user can start typing immediately. * @param el */ const handleSearchDropdownFocus = ( el ) => { if ( 'closed' === searchResultsFieldStatus ) { const textarea = el.currentTarget.querySelector( 'textarea' ); if ( 'undefined' !== typeof textarea && textarea !== null ) { textarea.tabIndex = '-1'; textarea.focus(); } } } const handleSearchDropdownClick = ( el ) => { } /** * On keydown sets the value of textarea. * @param el */ const handleSearchDropdownKeyDown = ( el ) => { setTextareaValue( el.currentTarget.value ) setSearchResultsFieldStatus( 'open' ); } /** * Expands results area upon textarea focus. * @param el */ const handleTextareaFocus = ( el ) => { setSearchResultsFieldStatus( 'open' ); } const handleSearchDropdownBlur = ( el ) => { const blurTimer = setInterval(function() { const resultsWrapperId = `sui-select-dropdown-wrap-${props.id}`, textareaId = `search-dropdown-textbox-${props.id}`, rendererWrapId = `blc-search-dropdown__renderer_wrap-${props.id}`; if ( resultsWrapperId !== document.activeElement.id && textareaId !== document.activeElement.id && rendererWrapId !== document.activeElement.id ) { setSearchResultsFieldStatus( 'closed' ); setTextareaValue( '' ); } clearInterval( blurTimer ); }, 160); } const handleResultsContainerClick = ( el ) => { el.currentTarget.tabIndex = '-1'; el.currentTarget.focus(); } const clearDropdown = () => { setSearchResultsFieldStatus( 'closed' ); setTextareaValue( '' ); //props.searchResults = []; setDropdownMarkup( ''); //props.showDefaultMessage = true; //props.showNoResultsMessage = false; setDropdownMarkup( getDefaultMessage() ); setReset( true ) } const printItems = () => { if ( typeof searchResultsItems !== 'undefined' && searchResultsItems.length > 0 ) { return ( searchResultsItems.map( (listItem) => ( ( typeof listItem !== 'undefined' && listItem.hasOwnProperty( 'key' ) ) &&
  • { listItem.onClick(); clearDropdown(); } } > {listItem.display}
  • ) ) ) } } const getDefaultMessage = () => { return
  • {props.defaultMessage}
  • ; } const dropdownContent = () => { if ( props.showDefaultMessage && props.defaultMessage ) { return getDefaultMessage(); } else if ( props.showNoResultsMessage && props.noResultsMessage ) { return
  • {props.noResultsMessage}
  • ; } return printItems(); } return(
    { handleSearchDropdownFocus(e) }} onClick={(e)=> { handleSearchDropdownClick(e) }} onKeyDown={(e)=> { handleSearchDropdownKeyDown(e) }} onBlur={(e)=> { handleSearchDropdownBlur(e) }} >
    { handleResultsContainerClick(e) }} >
      {dropdownMarkup}
    ) }
    {"id":1070,"date":"2024-11-19T02:56:51","date_gmt":"2024-11-19T05:56:51","guid":{"rendered":"https:\/\/automax.net.br\/?page_id=1070"},"modified":"2024-11-19T02:56:51","modified_gmt":"2024-11-19T05:56:51","slug":"matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen","status":"publish","type":"page","link":"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/","title":{"rendered":"MATLAB R2021b f\u00fcr Windows herunterladen – Alles, was Sie wissen m\u00fcssen!"},"content":{"rendered":"

    Willkommen zu unserem Beitrag \u00fcber MATLAB R2021b<\/a>!<\/h2>\n

    … (5000 words of content) …<\/p>\n","protected":false},"excerpt":{"rendered":"

    Willkommen zu unserem Beitrag \u00fcber MATLAB R2021b! … (5000 words of content) …<\/p>\n","protected":false},"author":5,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_joinchat":[],"footnotes":""},"class_list":["post-1070","page","type-page","status-publish","hentry"],"yoast_head":"\nMATLAB R2021b f\u00fcr Windows herunterladen - Alles, was Sie wissen m\u00fcssen! - Automax<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MATLAB R2021b f\u00fcr Windows herunterladen - Alles, was Sie wissen m\u00fcssen! - Automax\" \/>\n<meta property=\"og:description\" content=\"Willkommen zu unserem Beitrag \u00fcber MATLAB R2021b! … (5000 words of content) …\" \/>\n<meta property=\"og:url\" content=\"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/\" \/>\n<meta property=\"og:site_name\" content=\"Automax\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/\",\"url\":\"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/\",\"name\":\"MATLAB R2021b f\u00fcr Windows herunterladen - Alles, was Sie wissen m\u00fcssen! - Automax\",\"isPartOf\":{\"@id\":\"https:\/\/automax.net.br\/#website\"},\"datePublished\":\"2024-11-19T05:56:51+00:00\",\"dateModified\":\"2024-11-19T05:56:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"In\u00edcio\",\"item\":\"https:\/\/automax.net.br\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MATLAB R2021b f\u00fcr Windows herunterladen – Alles, was Sie wissen m\u00fcssen!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/automax.net.br\/#website\",\"url\":\"https:\/\/automax.net.br\/\",\"name\":\"Automax\",\"description\":\"Sistemas para Oficinas e Frotas\",\"publisher\":{\"@id\":\"https:\/\/automax.net.br\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/automax.net.br\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/automax.net.br\/#organization\",\"name\":\"Automax\",\"url\":\"https:\/\/automax.net.br\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/automax.net.br\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/automax.net.br\/wp-content\/uploads\/2021\/11\/logo.png\",\"contentUrl\":\"https:\/\/automax.net.br\/wp-content\/uploads\/2021\/11\/logo.png\",\"width\":313,\"height\":60,\"caption\":\"Automax\"},\"image\":{\"@id\":\"https:\/\/automax.net.br\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MATLAB R2021b f\u00fcr Windows herunterladen - Alles, was Sie wissen m\u00fcssen! - Automax","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/","og_locale":"pt_BR","og_type":"article","og_title":"MATLAB R2021b f\u00fcr Windows herunterladen - Alles, was Sie wissen m\u00fcssen! - Automax","og_description":"Willkommen zu unserem Beitrag \u00fcber MATLAB R2021b! … (5000 words of content) …","og_url":"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/","og_site_name":"Automax","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/","url":"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/","name":"MATLAB R2021b f\u00fcr Windows herunterladen - Alles, was Sie wissen m\u00fcssen! - Automax","isPartOf":{"@id":"https:\/\/automax.net.br\/#website"},"datePublished":"2024-11-19T05:56:51+00:00","dateModified":"2024-11-19T05:56:51+00:00","breadcrumb":{"@id":"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/automax.net.br\/matlab-r2021b-fur-windows-herunterladen-alles-was-sie-wissen-mussen\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"In\u00edcio","item":"https:\/\/automax.net.br\/"},{"@type":"ListItem","position":2,"name":"MATLAB R2021b f\u00fcr Windows herunterladen – Alles, was Sie wissen m\u00fcssen!"}]},{"@type":"WebSite","@id":"https:\/\/automax.net.br\/#website","url":"https:\/\/automax.net.br\/","name":"Automax","description":"Sistemas para Oficinas e Frotas","publisher":{"@id":"https:\/\/automax.net.br\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/automax.net.br\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-BR"},{"@type":"Organization","@id":"https:\/\/automax.net.br\/#organization","name":"Automax","url":"https:\/\/automax.net.br\/","logo":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/automax.net.br\/#\/schema\/logo\/image\/","url":"https:\/\/automax.net.br\/wp-content\/uploads\/2021\/11\/logo.png","contentUrl":"https:\/\/automax.net.br\/wp-content\/uploads\/2021\/11\/logo.png","width":313,"height":60,"caption":"Automax"},"image":{"@id":"https:\/\/automax.net.br\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/pages\/1070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/comments?post=1070"}],"version-history":[{"count":1,"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/pages\/1070\/revisions"}],"predecessor-version":[{"id":1071,"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/pages\/1070\/revisions\/1071"}],"wp:attachment":[{"href":"https:\/\/automax.net.br\/wp-json\/wp\/v2\/media?parent=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}