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

Close the pattern category when the right sidebar is open in zoom-out mode #56892

Merged
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
4 changes: 3 additions & 1 deletion packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function InserterMenu(
( patternCategory, filter ) => {
setSelectedPatternCategory( patternCategory );
setPatternFilter( filter );
__experimentalOnPatternCategorySelection?.();
__experimentalOnPatternCategorySelection?.( patternCategory );
},
[ setSelectedPatternCategory, __experimentalOnPatternCategorySelection ]
);
Expand Down Expand Up @@ -213,6 +213,8 @@ function InserterMenu(
focusSearch: () => {
searchRef.current.focus();
},
getSelectedPatternCategory: () => selectedPatternCategory,
selectPatternCategory: onClickPatternCategory,
} ) );

const showPatternPanel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { __ } from '@wordpress/i18n';
import { useEffect, useRef, useCallback } from '@wordpress/element';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { store as interfaceStore } from '@wordpress/interface';

/**
* Internal dependencies
Expand All @@ -38,6 +39,13 @@ export default function InserterSidebar() {
select( editSiteStore ).getEditedPostType()
)
);
const isRightSidebarOpen = useSelect(
( select ) =>
!! select( interfaceStore ).getActiveComplementaryArea(
editSiteStore.name
),
[]
);
const { __unstableSetEditorMode: setEditorMode } =
useDispatch( blockEditorStore );
const { __unstableGetEditorMode: getEditorMode } =
Expand All @@ -60,6 +68,15 @@ export default function InserterSidebar() {
},
} );

const onSelectPatternCategory = useCallback(
( category ) => {
if ( !! category ) {
closeGeneralSidebar();
}
},
[ closeGeneralSidebar ]
);

const libraryRef = useRef();
useEffect( () => {
libraryRef.current.focusSearch();
Expand Down Expand Up @@ -91,6 +108,19 @@ export default function InserterSidebar() {
[ location, setIsInserterOpened ]
);

useEffect(
function closePatternCategoryOnRightSidebarOpenInZoomOut() {
if (
getEditorMode() === 'zoom-out' &&
isRightSidebarOpen &&
!! libraryRef.current.getSelectedPatternCategory()
) {
libraryRef.current.selectPatternCategory( null );
}
},
[ getEditorMode, isRightSidebarOpen ]
);

return (
<div
ref={ inserterDialogRef }
Expand All @@ -114,7 +144,7 @@ export default function InserterSidebar() {
}
__experimentalFilterValue={ insertionPoint.filterValue }
__experimentalOnPatternCategorySelection={
closeGeneralSidebar
onSelectPatternCategory
}
__experimentalShouldZoomPatterns
ref={ libraryRef }
Expand Down