Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove viewport check from useZoomOut hook #66341

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 3 additions & 5 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,13 +20,12 @@ export function useZoomOut( zoomOut = true ) {
useDispatch( blockEditorStore )
);
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );
const isWideViewport = useViewportMatch( 'large' );

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

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

useEffect( () => {
if ( zoomOut && isWideViewport ) {
if ( zoomOut ) {
setZoomLevel( 'auto-scaled' );
} else {
resetZoomLevel();
}
}, [ zoomOut, setZoomLevel, resetZoomLevel, isWideViewport ] );
}, [ zoomOut, setZoomLevel, resetZoomLevel ] );
}
Loading