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' ) ) &&
\u0995\u09cd\u09b0\u09bf\u099f\u09be 4.4.8 \u098f\u0995\u099f\u09bf \u0989\u099a\u09cd\u099a \u09b8\u09ae\u09cd\u09aa\u09be\u09a6\u09a8\u09af\u09cb\u0997\u09cd\u09af \u09b0\u09c7\u09be \u09ae\u09c7\u09a1\u09bf\u09af\u09bc\u09be \u0995\u09cd\u09b0\u09bf\u09df\u09c7\u09b6\u09a8 \u09b8\u09ab\u099f\u0993\u09df\u09cd\u09af\u09be\u09b0\u0964 \u098f\u099f\u09bf \u099a\u09bf\u09a4\u09cd\u09b0, \u09a1\u09bf\u099c\u09be\u0987\u09a8 \u098f\u09ac\u0982 \u099a\u09bf\u09a4\u09cd\u09b0 \u09b8\u09ae\u09cd\u09aa\u09be\u09a6\u09a8\u09be\u09b0 \u099c\u09a8\u09cd\u09af \u09ac\u09cd\u09af\u09ac\u09b9\u09be\u09b0\u0995\u09be\u09b0\u09c0\u09a6\u09c7\u09b0 \u09aa\u099b\u09a8\u09cd\u09a6 \u09b9\u09cb\u0995\u0964<\/p>\n
\u0995\u09cd\u09b0\u09bf\u099f\u09be \u09ab\u09cd\u09b0\u09bf \u0995\u09cd\u09b0\u09bf\u09af\u09bc\u09c7\u099f\u09bf\u09ad \u0995\u09ae\u09a8\u09b8 \u09b2\u09be\u0987\u09b8\u09c7\u09a8\u09cd\u09b8\u09c7\u09b0 \u0986\u0993\u09a4\u09be\u09af\u09bc \u09b8\u09be\u09a7\u09be\u09b0\u09a3 \u09b8\u09ae\u09cd\u09aa\u09be\u09a6\u09a8\u09be \u098f\u09ac\u0982 \u09a1\u09be\u0995\u09a8\u0995 \u0995\u09be\u099c\u09c7 \u09ac\u09cd\u09af\u09ac\u09b9\u09be\u09b0 \u0995\u09b0\u09be \u09af\u09c7\u09a4\u09c7 \u09aa\u09be\u09b0\u09c7 \u098f\u09ac\u0982 \u0986\u09aa\u09a8\u09bf \u09b8\u09bf\u09b8\u09cd\u099f\u09c7\u09ae\u09c7 \u0986\u09aa\u09a8\u09be\u09b0 \u099a\u09be\u09b9\u09bf\u09a6\u09be\u09ae\u09a4 \u0997\u09c0\u099f\u09bf\u09ae\u09c7 \u09aa\u09b0\u09bf\u09ac\u09b0\u09cd\u09a4\u09a8 \u0995\u09b0\u09a4\u09c7 \u09aa\u09be\u09b0\u09ac\u09c7\u09a8\u0964<\/p>\n
\u09ae\u09c2\u09b2 \u09ac\u09c8\u09b6\u09bf\u09b7\u09cd\u099f\u09cd\u09af\u09b8\u09ae\u09c2\u09b9:<\/p>\n