Skip to content

Commit

Permalink
Fix: Activate zoom out on large viewport (#66308)
Browse files Browse the repository at this point in the history
* Activate zoom out on large viewport

* Reset zoom out when view-port change to medium

---------

Co-authored-by: PARTHVATALIYA <parthvataliya@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
  • Loading branch information
4 people authored Oct 22, 2024
1 parent ca8c191 commit c926d69
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 @@ -20,12 +21,13 @@ export function useZoomOut( zoomOut = true ) {
useDispatch( blockEditorStore )
);
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );
const isWideViewport = useViewportMatch( 'large' );

useEffect( () => {
const isZoomOutOnMount = isZoomOut();

return () => {
if ( isZoomOutOnMount ) {
if ( isZoomOutOnMount && isWideViewport ) {
setZoomLevel( 50 );
} else {
resetZoomLevel();
Expand All @@ -34,10 +36,10 @@ export function useZoomOut( zoomOut = true ) {
}, [] );

useEffect( () => {
if ( zoomOut ) {
if ( zoomOut && isWideViewport ) {
setZoomLevel( 50 );
} else {
resetZoomLevel();
}
}, [ zoomOut, setZoomLevel, resetZoomLevel ] );
}, [ zoomOut, setZoomLevel, resetZoomLevel, isWideViewport ] );
}

0 comments on commit c926d69

Please sign in to comment.