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

Site Editor: Fix inserter can't be closed #28590

Merged
merged 2 commits into from
Feb 4, 2021
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
34 changes: 34 additions & 0 deletions packages/e2e-tests/specs/experiments/site-editor-inserter.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* WordPress dependencies
*/
import { trashAllPosts, activateTheme } from '@wordpress/e2e-test-utils';

/**
* Internal dependencies
*/
import { siteEditor } from '../../experimental-features';

describe( 'Site Editor Inserter', () => {
beforeAll( async () => {
await activateTheme( 'tt1-blocks' );
await trashAllPosts( 'wp_template' );
await trashAllPosts( 'wp_template_part' );
} );
afterAll( async () => {
await activateTheme( 'twentytwentyone' );
} );
beforeEach( async () => {
await siteEditor.visit();
} );

it( 'inserter toggle button should toggle global inserter', async () => {
await page.click( '.edit-site-header-toolbar__inserter-toggle' );
await page.waitForSelector( '.edit-site-editor__inserter-panel', {
visible: true,
} );
await page.click( '.edit-site-header-toolbar__inserter-toggle' );
await page.waitForSelector( '.edit-site-editor__inserter-panel', {
hidden: true,
} );
} );
} );
17 changes: 14 additions & 3 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* WordPress dependencies
*/
import { useRef } from '@wordpress/element';
import { useViewportMatch } from '@wordpress/compose';
import {
BlockNavigationDropdown,
Expand All @@ -25,6 +26,7 @@ import DocumentActions from './document-actions';
import TemplateDetails from '../template-details';

export default function Header( { openEntitiesSavedStates } ) {
const inserterButton = useRef();
const {
deviceType,
entityTitle,
Expand Down Expand Up @@ -77,12 +79,21 @@ export default function Header( { openEntitiesSavedStates } ) {
<div className="edit-site-header_start">
<div className="edit-site-header__toolbar">
<Button
ref={ inserterButton }
isPrimary
isPressed={ isInserterOpen }
className="edit-site-header-toolbar__inserter-toggle"
onClick={ () =>
setIsInserterOpened( ! isInserterOpen )
}
onMouseDown={ ( event ) => {
event.preventDefault();
} }
onClick={ () => {
if ( isInserterOpen ) {
// Focusing the inserter button closes the inserter popover
inserterButton.current.focus();
} else {
setIsInserterOpened( true );
}
} }
icon={ plus }
label={ _x(
'Add block',
Expand Down