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

Fix: Block inserter panel visibility issue on mobile and tablet while building a page or post #68791

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
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ import {
} from '@wordpress/blocks';
import { __experimentalTruncate as Truncate } from '@wordpress/components';
import { ENTER, isAppleOS } from '@wordpress/keycodes';
import { useSelect } from '@wordpress/data';
import { useViewportMatch } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockIcon from '../block-icon';
import { InserterListboxItem } from '../inserter-listbox';
import InserterDraggableBlocks from '../inserter-draggable-blocks';
import { store as blockEditorStore } from '../../store';
import { unlock } from '../../lock-unlock';

function InserterListItem( {
className,
Expand Down Expand Up @@ -54,6 +58,17 @@ function InserterListItem( {
( isReusableBlock( item ) && item.syncStatus !== 'unsynced' ) ||
isTemplatePart( item );

const { setInserterIsOpened } = useSelect( ( select ) => {
const { getSettings } = unlock( select( blockEditorStore ) );

return {
setInserterIsOpened:
getSettings().__experimentalSetIsInserterOpened,
};
}, [] );

const isMobileViewport = useViewportMatch( 'medium', '<' );

return (
<InserterDraggableBlocks
isEnabled={ isDraggable && ! item.isDisabled }
Expand All @@ -75,6 +90,9 @@ function InserterListItem( {
onHover( null );
onDragStart( event );
}
if ( isMobileViewport ) {
setInserterIsOpened( false );
}
} }
onDragEnd={ ( event ) => {
isDraggingRef.current = false;
Expand Down
27 changes: 18 additions & 9 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,19 @@ function InserterMenu(
},
ref
) {
const { isZoomOutMode, hasSectionRootClientId } = useSelect( ( select ) => {
const { isZoomOut, getSectionRootClientId } = unlock(
select( blockEditorStore )
);
const { isZoomOutMode, hasSectionRootClientId, setInserterIsOpened } =
useSelect( ( select ) => {
const { isZoomOut, getSectionRootClientId, getSettings } = unlock(
select( blockEditorStore )
);

return {
isZoomOutMode: isZoomOut(),
hasSectionRootClientId: !! getSectionRootClientId(),
};
}, [] );
return {
isZoomOutMode: isZoomOut(),
hasSectionRootClientId: !! getSectionRootClientId(),
setInserterIsOpened:
getSettings().__experimentalSetIsInserterOpened,
};
}, [] );

const [ filterValue, setFilterValue, delayedFilterValue ] =
useDebouncedInput( __experimentalFilterValue );
Expand All @@ -75,6 +78,7 @@ function InserterMenu(
const [ selectedMediaCategory, setSelectedMediaCategory ] =
useState( null );
const isLargeViewport = useViewportMatch( 'large' );
const isMobileViewport = useViewportMatch( 'medium', '<' );

function getInitialTab() {
if ( __experimentalInitialTab ) {
Expand Down Expand Up @@ -115,6 +119,11 @@ function InserterMenu(
);
onSelect( blocks );

// Checks the mobile viewport and closes the inserter panel
if ( isMobileViewport ) {
setInserterIsOpened( false );
}

// Check for focus loss due to filtering blocks by selected block type
window.requestAnimationFrame( () => {
if (
Expand Down
Loading