Skip to content

Commit

Permalink
Activate zoom out only on large viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano committed Oct 25, 2024
1 parent fb9466b commit 4c8428b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useEffect, useRef } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -22,6 +23,7 @@ export function useZoomOut( zoomOut = true ) {

const originalEditingModeRef = useRef( null );
const mode = __unstableGetEditorMode();
const isWideViewport = useViewportMatch( 'large' );

useEffect( () => {
// Only set this on mount so we know what to return to when we unmount.
Expand All @@ -43,7 +45,9 @@ export function useZoomOut( zoomOut = true ) {

// The effect opens the zoom-out view if we want it open and it's not currently in zoom-out mode.
useEffect( () => {
if ( zoomOut && mode !== 'zoom-out' ) {
if ( ! isWideViewport ) {
setZoomLevel( 100 );
} else if ( zoomOut && mode !== 'zoom-out' ) {
__unstableSetEditorMode( 'zoom-out' );
setZoomLevel( 50 );
} else if (
Expand All @@ -59,5 +63,6 @@ export function useZoomOut( zoomOut = true ) {
__unstableSetEditorMode,
zoomOut,
setZoomLevel,
isWideViewport,
] ); // Mode is deliberately excluded from the dependencies so that the effect does not run when mode changes.
}

0 comments on commit 4c8428b

Please sign in to comment.