Skip to content

Commit

Permalink
Inserter: Only always show the inserter when the zoom out experiment …
Browse files Browse the repository at this point in the history
…is on (WordPress#61856)

Co-authored-by: scruffian <[email protected]>
Co-authored-by: draganescu <[email protected]>
Co-authored-by: richtabor <[email protected]>
Co-authored-by: ellatrix <[email protected]>
  • Loading branch information
5 people authored and patil-vipul committed Jun 17, 2024
1 parent b6df809 commit 6393e99
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
71 changes: 47 additions & 24 deletions packages/editor/src/components/inserter-sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
__experimentalLibrary as Library,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useViewportMatch } from '@wordpress/compose';
import {
useViewportMatch,
__experimentalUseDialog as useDialog,
} from '@wordpress/compose';
import { useCallback, useRef } from '@wordpress/element';
import { store as preferencesStore } from '@wordpress/preferences';
import { ESCAPE } from '@wordpress/keycodes';
Expand Down Expand Up @@ -52,6 +55,10 @@ export default function InserterSidebar( {
const { setIsInserterOpened } = useDispatch( editorStore );

const isMobileViewport = useViewportMatch( 'medium', '<' );
const [ inserterDialogRef, inserterDialogProps ] = useDialog( {
onClose: () => setIsInserterOpened( false ),
focusOnMount: true,
} );
const libraryRef = useRef();

// When closing the inserter, focus should return to the toggle button.
Expand All @@ -70,30 +77,46 @@ export default function InserterSidebar( {
[ closeInserterSidebar ]
);

return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div onKeyDown={ closeOnEscape } className="editor-inserter-sidebar">
<div className="editor-inserter-sidebar__content">
<Library
showMostUsedBlocks={ showMostUsedBlocks }
showInserterHelpPanel
shouldFocusBlock={ isMobileViewport }
rootClientId={
blockSectionRootClientId ?? insertionPoint.rootClientId
}
__experimentalInsertionIndex={
insertionPoint.insertionIndex
}
__experimentalInitialTab={ insertionPoint.tab }
__experimentalInitialCategory={ insertionPoint.category }
__experimentalFilterValue={ insertionPoint.filterValue }
__experimentalOnPatternCategorySelection={
isRightSidebarOpen ? closeGeneralSidebar : undefined
}
ref={ libraryRef }
onClose={ closeInserterSidebar }
/>
const inserterContents = (
<div className="editor-inserter-sidebar__content">
<Library
showMostUsedBlocks={ showMostUsedBlocks }
showInserterHelpPanel
shouldFocusBlock={ isMobileViewport }
rootClientId={
blockSectionRootClientId ?? insertionPoint.rootClientId
}
__experimentalInsertionIndex={ insertionPoint.insertionIndex }
__experimentalInitialTab={ insertionPoint.tab }
__experimentalInitialCategory={ insertionPoint.category }
__experimentalFilterValue={ insertionPoint.filterValue }
__experimentalOnPatternCategorySelection={
isRightSidebarOpen ? closeGeneralSidebar : undefined
}
ref={ libraryRef }
onClose={ closeInserterSidebar }
/>
</div>
);

if ( window.__experimentalEnableZoomedOutPatternsTab ) {
return (
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
<div
onKeyDown={ closeOnEscape }
className="editor-inserter-sidebar"
>
{ inserterContents }
</div>
);
}
return (
<div
ref={ inserterDialogRef }
{ ...inserterDialogProps }
className="editor-inserter-sidebar"
>
{ inserterContents }
</div>
);
}
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/inserting-blocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ test.describe( 'Inserting blocks (@firefox, @webkit)', () => {
page.getByRole( 'region', {
name: 'Block Library',
} )
).toBeVisible();
).toBeHidden();
} );

test( 'shows block preview when hovering over block in inserter', async ( {
Expand Down

0 comments on commit 6393e99

Please sign in to comment.