Skip to content

Commit c86612b

Browse files
getdavetalldanjeryjramonjddraganescu
authored andcommitted
Disable Zoom Out if no section root to allow for Theme opt in (#67232)
* Disable toolbar and auto inserter behaviour if no section root * Remove useless coercion Co-authored-by: Ramon <[email protected]> * Remove more coercion copy/paste Co-authored-by: Ramon <[email protected]> * Add section root to Zoom Out e2e test * Add test coverage * Add some test coverage * Try e2e test fix by reverting all template part changes in Theme * Remove need to exit Zoom Out * Ensure a main tag * Update tests to expect the click-through behavior * Simplify selection --------- Co-authored-by: getdave <[email protected]> Co-authored-by: talldan <[email protected]> Co-authored-by: jeryj <[email protected]> Co-authored-by: ramonjd <[email protected]> Co-authored-by: draganescu <[email protected]>
1 parent c5ecfff commit c86612b

File tree

4 files changed

+66
-7
lines changed

4 files changed

+66
-7
lines changed

packages/block-editor/src/components/inserter/menu.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ function InserterMenu(
5858
( select ) => unlock( select( blockEditorStore ) ).isZoomOut(),
5959
[]
6060
);
61+
const hasSectionRootClientId = useSelect(
62+
( select ) =>
63+
!! unlock( select( blockEditorStore ) ).getSectionRootClientId(),
64+
[]
65+
);
6166
const [ filterValue, setFilterValue, delayedFilterValue ] =
6267
useDebouncedInput( __experimentalFilterValue );
6368
const [ hoveredItem, setHoveredItem ] = useState( null );
@@ -81,7 +86,9 @@ function InserterMenu(
8186
const [ selectedTab, setSelectedTab ] = useState( getInitialTab() );
8287

8388
const shouldUseZoomOut =
84-
selectedTab === 'patterns' || selectedTab === 'media';
89+
hasSectionRootClientId &&
90+
( selectedTab === 'patterns' || selectedTab === 'media' );
91+
8592
useZoomOut( shouldUseZoomOut && isLargeViewport );
8693

8794
const [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ] =

packages/editor/src/components/header/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
PATTERN_POST_TYPE,
3131
NAVIGATION_POST_TYPE,
3232
} from '../../store/constants';
33+
import { unlock } from '../../lock-unlock';
3334

3435
const toolbarVariations = {
3536
distractionFreeDisabled: { y: '-50px' },
@@ -100,6 +101,13 @@ function Header( {
100101
( ! hasBlockSelection || isBlockToolsCollapsed ) &&
101102
! isTooNarrowForDocumentBar;
102103
const hasBackButton = useHasBackButton();
104+
105+
const hasSectionRootClientId = useSelect(
106+
( select ) =>
107+
!! unlock( select( blockEditorStore ) ).getSectionRootClientId(),
108+
[]
109+
);
110+
103111
/*
104112
* The edit-post-header classname is only kept for backward compatability
105113
* as some plugins might be relying on its presence.
@@ -167,9 +175,11 @@ function Header( {
167175
forceIsAutosaveable={ forceIsDirty }
168176
/>
169177

170-
{ canBeZoomedOut && isWideViewport && (
171-
<ZoomOutToggle disabled={ forceDisableBlockTools } />
172-
) }
178+
{ canBeZoomedOut &&
179+
isWideViewport &&
180+
hasSectionRootClientId && (
181+
<ZoomOutToggle disabled={ forceDisableBlockTools } />
182+
) }
173183

174184
{ ( isWideViewport || ! showIconLabels ) && (
175185
<PinnedItems.Slot scope="core" />

test/e2e/specs/editor/various/parsing-patterns.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ test.describe( 'Parsing patterns', () => {
3737
} );
3838
} );
3939

40-
// Exit zoom out mode and select the inner buttons block to ensure
40+
// Select the inner buttons block to ensure
4141
// the correct insertion point is selected.
42-
await page.getByRole( 'button', { name: 'Zoom Out' } ).click();
4342
await editor.selectBlocks(
4443
editor.canvas.locator( 'role=document[name="Block: Button"i]' )
4544
);

test/e2e/specs/site-editor/zoom-out.spec.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
55

66
const EDITOR_ZOOM_OUT_CONTENT = `
7-
<!-- wp:group {"style":{"spacing":{"padding":{"top":"0","bottom":"0","left":"0","right":"0"}},"dimensions":{"minHeight":"100vh"}},"backgroundColor":"base-2","layout":{"type":"flex","orientation":"vertical","verticalAlignment":"space-between"}} -->
7+
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} -->
8+
<main class="wp-block-group"><!-- wp:group {"style":{"spacing":{"padding":{"top":"0","bottom":"0","left":"0","right":"0"}},"dimensions":{"minHeight":"100vh"}},"backgroundColor":"base-2","layout":{"type":"flex","orientation":"vertical","verticalAlignment":"space-between"}} -->
89
<div class="wp-block-group has-base-2-background-color has-background" style="min-height:100vh;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0"><!-- wp:paragraph -->
910
<p>First Section Start</p>
1011
<!-- /wp:paragraph -->
@@ -58,6 +59,21 @@ const EDITOR_ZOOM_OUT_CONTENT = `
5859
<!-- wp:paragraph -->
5960
<p>Fourth Section End</p>
6061
<!-- /wp:paragraph --></div>
62+
<!-- /wp:group --></main>
63+
<!-- /wp:group -->`;
64+
65+
const EDITOR_ZOOM_OUT_CONTENT_NO_SECTION_ROOT = `<!-- wp:group {"style":{"spacing":{"padding":{"top":"0","bottom":"0","left":"0","right":"0"}},"dimensions":{"minHeight":"100vh"}},"backgroundColor":"base-2","layout":{"type":"flex","orientation":"vertical","verticalAlignment":"space-between"}} -->
66+
<div class="wp-block-group has-base-2-background-color has-background" style="min-height:100vh;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0"><!-- wp:paragraph -->
67+
<p>First Section Start</p>
68+
<!-- /wp:paragraph -->
69+
70+
<!-- wp:paragraph {"style":{"layout":{"selfStretch":"fit","flexSize":null}}} -->
71+
<p>First Section Center</p>
72+
<!-- /wp:paragraph -->
73+
74+
<!-- wp:paragraph -->
75+
<p>First Section End</p>
76+
<!-- /wp:paragraph --></div>
6177
<!-- /wp:group -->`;
6278

6379
test.describe( 'Zoom Out', () => {
@@ -67,6 +83,8 @@ test.describe( 'Zoom Out', () => {
6783

6884
test.afterAll( async ( { requestUtils } ) => {
6985
await requestUtils.activateTheme( 'twentytwentyone' );
86+
await requestUtils.deleteAllTemplates( 'wp_template' );
87+
await requestUtils.deleteAllTemplates( 'wp_template_part' );
7088
} );
7189

7290
test.beforeEach( async ( { admin } ) => {
@@ -215,4 +233,29 @@ test.describe( 'Zoom Out', () => {
215233
await expect( thirdSectionEnd ).toBeInViewport();
216234
await expect( fourthSectionStart ).not.toBeInViewport();
217235
} );
236+
237+
test( 'Zoom Out cannot be activated when the section root is missing', async ( {
238+
page,
239+
editor,
240+
} ) => {
241+
await editor.setContent( EDITOR_ZOOM_OUT_CONTENT_NO_SECTION_ROOT );
242+
243+
// Check that the Zoom Out toggle button is not visible.
244+
await expect(
245+
page.getByRole( 'button', { name: 'Zoom Out' } )
246+
).toBeHidden();
247+
248+
// Check that activating the Patterns tab in the Inserter does not activate
249+
// Zoom Out.
250+
await page
251+
.getByRole( 'button', {
252+
name: 'Block Inserter',
253+
exact: true,
254+
} )
255+
.click();
256+
257+
await page.getByRole( 'tab', { name: 'Patterns' } ).click();
258+
259+
await expect( page.locator( '.is-zoomed-out' ) ).toBeHidden();
260+
} );
218261
} );

0 commit comments

Comments
 (0)