diff --git a/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js b/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js index e96d1b2321eb2..fcb9a1980db99 100644 --- a/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js +++ b/packages/block-editor/src/components/inserter/block-patterns-explorer/patterns-list.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { useMemo, useEffect, useRef } from '@wordpress/element'; +import { useMemo, useEffect, useRef, useState } from '@wordpress/element'; import { _n, sprintf } from '@wordpress/i18n'; import { useDebounce } from '@wordpress/compose'; import { __experimentalHeading as Heading } from '@wordpress/components'; @@ -114,6 +114,14 @@ function PatternList( { searchValue, selectedCategory, patternCategories } ) { container ); + // Reset page when search value changes. + const [ previousSearchValue, setPreviousSearchValue ] = + useState( searchValue ); + if ( searchValue !== previousSearchValue ) { + setPreviousSearchValue( searchValue ); + pagingProps.changePage( 1 ); + } + const hasItems = !! filteredBlockPatterns?.length; return (
() => onHover( null ), [] ); + const onSetPatternSyncFilter = useCallback( + ( value ) => { + setPatternSyncFilter( value ); + changePage( 1 ); + }, + [ setPatternSyncFilter, changePage ] + ); + const onSetPatternSourceFilter = useCallback( + ( value ) => { + setPatternSourceFilter( value ); + changePage( 1 ); + }, + [ setPatternSourceFilter, changePage ] + ); + return (