Skip to content

Commit

Permalink
Handle zoom out when changing device preview (#65444)
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu authored and gutenbergplugin committed Sep 20, 2024
1 parent a784d78 commit 0237d6e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/editor/src/components/preview-dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ActionItem } from '@wordpress/interface';
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import { store as blockEditorStore } from '@wordpress/block-editor';
import PostPreviewButton from '../post-preview-button';

export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
Expand All @@ -44,6 +45,12 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
};
}, [] );
const { setDeviceType } = useDispatch( editorStore );
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );

const handleDevicePreviewChange = ( newDeviceType ) => {
setDeviceType( newDeviceType );
__unstableSetEditorMode( 'edit' );
};

const isMobile = useViewportMatch( 'medium', '<' );
if ( isMobile ) {
Expand Down Expand Up @@ -113,7 +120,7 @@ export default function PreviewDropdown( { forceIsAutosaveable, disabled } ) {
<MenuItemsChoice
choices={ choices }
value={ deviceType }
onSelect={ setDeviceType }
onSelect={ handleDevicePreviewChange }
/>
</MenuGroup>
{ isTemplate && (
Expand Down

0 comments on commit 0237d6e

Please sign in to comment.