Skip to content

Commit

Permalink
Inserter: Add closeQuickInserter prop to QuickInserter for mobile dev…
Browse files Browse the repository at this point in the history
…ices
  • Loading branch information
yogeshbhutkar committed Nov 27, 2024
1 parent 0db7ff6 commit f595402
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/block-editor/src/components/inserter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class Inserter extends Component {
isAppender={ isAppender }
prioritizePatterns={ prioritizePatterns }
selectBlockOnInsert={ selectBlockOnInsert }
closeQuickInserter={ onClose }
/>
);
}
Expand Down
12 changes: 12 additions & 0 deletions packages/block-editor/src/components/inserter/quick-inserter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +33,7 @@ export default function QuickInserter( {
isAppender,
prioritizePatterns,
selectBlockOnInsert,
closeQuickInserter,
hasSearch = true,
} ) {
const [ filterValue, setFilterValue ] = useState( '' );
Expand All @@ -54,6 +56,8 @@ export default function QuickInserter( {
true
);

const isMobileDevice = useViewportMatch( 'small', '<' );

const { setInserterIsOpened, insertionIndex } = useSelect(
( select ) => {
const { getSettings, getBlockIndex, getBlockCount } =
Expand Down Expand Up @@ -86,6 +90,14 @@ 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 &&
closeQuickInserter &&
typeof closeQuickInserter === 'function'
) {
closeQuickInserter();
}

setInserterIsOpened( {
filterValue,
onSelect,
Expand Down

0 comments on commit f595402

Please sign in to comment.