Skip to content

Commit

Permalink
fix: canvas zooms in when pattern inserter closed after opening block…
Browse files Browse the repository at this point in the history
… inserter once
  • Loading branch information
yogeshbhutkar committed Dec 26, 2024
1 parent 368e81d commit f655588
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
useCallback,
useMemo,
useRef,
useEffect,
useLayoutEffect,
} from '@wordpress/element';
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
Expand Down Expand Up @@ -74,11 +75,6 @@ function InserterMenu(
useState( null );
const isLargeViewport = useViewportMatch( 'large' );

const selectedTab = useSelect( ( select ) =>
select( blockEditorStore ).getSelectedTab()
);
const { setSelectedTab } = useDispatch( blockEditorStore );

function getInitialTab() {
if ( __experimentalInitialTab ) {
return __experimentalInitialTab;
Expand All @@ -91,9 +87,13 @@ function InserterMenu(
return 'blocks';
}

useLayoutEffect( () => {
setSelectedTab( getInitialTab() );
}, [] );
const [ selectedTab, setSelectedTab ] = useState( getInitialTab() );
const { setSelectedTab: setInserterSelectedTab } =
useDispatch( blockEditorStore );

useEffect( () => {
setInserterSelectedTab( selectedTab );
}, [ selectedTab, setInserterSelectedTab ] );

const shouldUseZoomOut =
hasSectionRootClientId &&
Expand Down

0 comments on commit f655588

Please sign in to comment.