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

Inserter: Auto-close the inserter unless the zoom out experiment is on. #61856

Merged
merged 1 commit into from
May 22, 2024
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
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
Loading