Skip to content

Commit

Permalink
Only inserter on mount
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Apr 30, 2024
1 parent c48a820 commit c9f6812
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { forwardRef, useState, useCallback, useMemo } from '@wordpress/element';
import {
forwardRef,
useState,
useCallback,
useMemo,
useRef,
} from '@wordpress/element';
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
Expand Down Expand Up @@ -53,7 +59,7 @@ function InserterMenu(
const [ patternFilter, setPatternFilter ] = useState( 'all' );
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const [ selectedTab, setSelectedTab ] = useState( null );
const [ selectedTab, setSelectedTab ] = useState( 'blocks' );

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
Expand Down Expand Up @@ -231,17 +237,18 @@ function InserterMenu(
setSelectedTab( value );
};

const hasAutoFocused = useRef( false );
const searchRef = useRefEffect( ( element ) => {
if ( element ) {
element.focus();
if ( element && hasAutoFocused.current === false ) {
hasAutoFocused.current = true;
window.requestAnimationFrame( () => element.focus() );
}
} );
}, [] );

const inserterSearch = useMemo( () => {
if ( selectedTab === 'media' ) {
return null;
}

return (
<>
<SearchControl
Expand Down

0 comments on commit c9f6812

Please sign in to comment.