Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserter: Try deferring search value instead of debouncing #58058

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
useMemo,
useImperativeHandle,
useRef,
useDeferredValue,
} from '@wordpress/element';
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useDebouncedInput } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -48,8 +48,10 @@ function InserterMenu(
},
ref
) {
const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
const [ filterValue, setFilterValue ] = useState(
__experimentalFilterValue
);
const deferredFilterValue = useDeferredValue( filterValue );
const [ hoveredItem, setHoveredItem ] = useState( null );
const [ selectedPatternCategory, setSelectedPatternCategory ] =
useState( null );
Expand Down Expand Up @@ -200,12 +202,12 @@ function InserterMenu(

const showPatternPanel =
selectedTab === 'patterns' &&
! delayedFilterValue &&
! deferredFilterValue &&
selectedPatternCategory;
const showAsTabs = ! delayedFilterValue && ( showPatterns || showMedia );
const showAsTabs = ! deferredFilterValue && ( showPatterns || showMedia );
const showMediaPanel =
selectedTab === 'media' &&
! delayedFilterValue &&
! deferredFilterValue &&
selectedMediaCategory;

const handleSetSelectedTab = ( value ) => {
Expand Down Expand Up @@ -235,10 +237,10 @@ function InserterMenu(
placeholder={ __( 'Search' ) }
ref={ searchRef }
/>
{ !! delayedFilterValue && (
{ !! deferredFilterValue && (
<div className="block-editor-inserter__no-tab-container">
<InserterSearchResults
filterValue={ delayedFilterValue }
filterValue={ deferredFilterValue }
onSelect={ onSelect }
onHover={ onHover }
onHoverPattern={ onHoverPattern }
Expand All @@ -261,7 +263,7 @@ function InserterMenu(
tabsContents={ inserterTabsContents }
/>
) }
{ ! delayedFilterValue && ! showAsTabs && (
{ ! deferredFilterValue && ! showAsTabs && (
<div className="block-editor-inserter__no-tab-container">
{ blocksTab }
</div>
Expand Down
Loading