diff --git a/packages/block-editor/src/components/inserter/index.js b/packages/block-editor/src/components/inserter/index.js index 1af81d0231a1a8..f51715233c7562 100644 --- a/packages/block-editor/src/components/inserter/index.js +++ b/packages/block-editor/src/components/inserter/index.js @@ -173,6 +173,7 @@ class Inserter extends Component { isAppender={ isAppender } prioritizePatterns={ prioritizePatterns } selectBlockOnInsert={ selectBlockOnInsert } + onClose={ onClose } /> ); } diff --git a/packages/block-editor/src/components/inserter/quick-inserter.js b/packages/block-editor/src/components/inserter/quick-inserter.js index 9f393a7ce15202..fbda189552ea4e 100644 --- a/packages/block-editor/src/components/inserter/quick-inserter.js +++ b/packages/block-editor/src/components/inserter/quick-inserter.js @@ -19,6 +19,7 @@ import useInsertionPoint from './hooks/use-insertion-point'; import usePatternsState from './hooks/use-patterns-state'; import useBlockTypesState from './hooks/use-block-types-state'; import { store as blockEditorStore } from '../../store'; +import { useViewportMatch } from '@wordpress/compose'; const SEARCH_THRESHOLD = 6; const SHOWN_BLOCK_TYPES = 6; @@ -32,6 +33,7 @@ export default function QuickInserter( { isAppender, prioritizePatterns, selectBlockOnInsert, + onClose, hasSearch = true, } ) { const [ filterValue, setFilterValue ] = useState( '' ); @@ -54,6 +56,8 @@ export default function QuickInserter( { true ); + const isMobileDevice = useViewportMatch( 'small', '<' ); + const { setInserterIsOpened, insertionIndex } = useSelect( ( select ) => { const { getSettings, getBlockIndex, getBlockCount } = @@ -86,6 +90,10 @@ export default function QuickInserter( { // When clicking Browse All select the appropriate block so as // the insertion point can work as expected. const onBrowseAll = () => { + if ( isMobileDevice ) { + onClose?.(); + } + setInserterIsOpened( { filterValue, onSelect,