Skip to content

Commit

Permalink
Hide inserter's block preview when searching (#23827)
Browse files Browse the repository at this point in the history
* hide block preview on inserter

* handle onUnmount internally

* fix tests
  • Loading branch information
ntsekouras authored Jul 13, 2020
1 parent 815deac commit c2af546
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ export function BlockTypesTab( {
return result;
}, [ filteredItems, collections ] );

// hide block preview on unmount
useEffect( () => () => onHover( null ), [] );

// Announce search results on change
useEffect( () => {
const resultsFoundMessage = sprintf(
Expand Down
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ function InserterMenu( {
{ /* the following div is necessary to fix the sticky position of the search form */ }
<div className="block-editor-inserter__content">
<InserterSearchForm
onChange={ setFilterValue }
onChange={ ( value ) => {
if ( hoveredItem ) setHoveredItem( null );
setFilterValue( value );
} }
value={ filterValue }
/>
{ ( showPatterns || hasReusableBlocks ) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ jest.mock( '@wordpress/data/src/components/use-dispatch', () => {
const debouncedSpeak = jest.fn();

function InserterBlockList( props ) {
return <BlockTypesTab debouncedSpeak={ debouncedSpeak } { ...props } />;
return (
<BlockTypesTab
debouncedSpeak={ debouncedSpeak }
onHover={ () => {} }
{ ...props }
/>
);
}

const initializeAllClosedMenuState = ( propOverrides ) => {
Expand Down

0 comments on commit c2af546

Please sign in to comment.