Skip to content

Commit

Permalink
Remove viewport check from useZoomOut hook
Browse files Browse the repository at this point in the history
The useZoomOut hook should not be responsible for checking viewport width. It should respect the desired zoom out level passed by the condition. We should decide if we want to enter zoom out or not where we implement the zoom out hook (the inserter menu).
  • Loading branch information
jeryj committed Oct 23, 2024
1 parent 609d573 commit 4e2af1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '@wordpress/element';
import { VisuallyHidden, SearchControl, Popover } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useDebouncedInput } from '@wordpress/compose';
import { useDebouncedInput, useViewportMatch } from '@wordpress/compose';
import { useSelect } from '@wordpress/data';

/**
Expand Down Expand Up @@ -67,6 +67,8 @@ function InserterMenu(
const [ patternFilter, setPatternFilter ] = useState( 'all' );
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const isLargeViewport = ! useViewportMatch( 'medium', '<' );

function getInitialTab() {
if ( __experimentalInitialTab ) {
return __experimentalInitialTab;
Expand All @@ -80,7 +82,7 @@ function InserterMenu(

const shouldUseZoomOut =
selectedTab === 'patterns' || selectedTab === 'media';
useZoomOut( shouldUseZoomOut );
useZoomOut( shouldUseZoomOut && isLargeViewport );

const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =
useInsertionPoint( {
Expand Down
4 changes: 1 addition & 3 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { useEffect } from '@wordpress/element';
*/
import { store as blockEditorStore } from '../store';
import { unlock } from '../lock-unlock';
import { useViewportMatch } from '@wordpress/compose';

/**
* A hook used to set the editor mode to zoomed out mode, invoking the hook sets the mode.
Expand All @@ -21,7 +20,6 @@ export function useZoomOut( zoomOut = true ) {
useDispatch( blockEditorStore )
);
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );
const isWideViewport = useViewportMatch( 'large' );

useEffect( () => {
const isZoomOutOnMount = isZoomOut();
Expand All @@ -41,5 +39,5 @@ export function useZoomOut( zoomOut = true ) {
} else {
resetZoomLevel();
}
}, [ zoomOut, setZoomLevel, resetZoomLevel, isWideViewport ] );
}, [ zoomOut, setZoomLevel, resetZoomLevel ] );
}

0 comments on commit 4e2af1e

Please sign in to comment.