Skip to content

Commit

Permalink
Patterns: Disable the preview option button when editing (#53913)
Browse files Browse the repository at this point in the history
* Don't show the preview options button when editing patterns

* Refactor with FOCUSABLE_ENTITIES

* Use disabled view icon

* Use isEnabled prop

* Also set 'disableOpenOnArrowDown'

* Fix e2e test

* Use `toBeDisabled`

---------

Co-authored-by: George Mamadashvili <[email protected]>
  • Loading branch information
t-hamano and Mamaduka authored Aug 29, 2023
1 parent 4f6d1b3 commit 2db2dc0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 36 deletions.
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/preview-options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default function PreviewOptions( {
const toggleProps = {
className: 'block-editor-post-preview__button-toggle',
disabled: ! isEnabled,
__experimentalIsFocusable: ! isEnabled,
children: viewLabel,
};
const menuProps = {
Expand All @@ -53,6 +54,7 @@ export default function PreviewOptions( {
menuProps={ menuProps }
icon={ deviceIcons[ deviceType.toLowerCase() ] }
label={ label || __( 'Preview' ) }
disableOpenOnArrowDown={ ! isEnabled }
>
{ ( renderProps ) => (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import EditorCanvas from './editor-canvas';
import EditorCanvasContainer from '../editor-canvas-container';
import useSiteEditorSettings from './use-site-editor-settings';
import { store as editSiteStore } from '../../store';
import { FOCUSABLE_ENTITIES } from './constants';
import { FOCUSABLE_ENTITIES } from '../../utils/constants';
import { unlock } from '../../lock-unlock';
import PageContentFocusManager from '../page-content-focus-manager';

Expand Down
69 changes: 35 additions & 34 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
useHasEditorCanvasContainer,
} from '../editor-canvas-container';
import { unlock } from '../../lock-unlock';
import { FOCUSABLE_ENTITIES } from '../../utils/constants';

const { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );

Expand Down Expand Up @@ -156,8 +157,7 @@ export default function HeaderEditMode() {

const hasDefaultEditorCanvasView = ! useHasEditorCanvasContainer();

const isFocusMode =
templateType === 'wp_template_part' || templateType === 'wp_navigation';
const isFocusMode = FOCUSABLE_ENTITIES.includes( templateType );

/* translators: button label text should, if possible, be under 16 characters. */
const longLabel = _x(
Expand Down Expand Up @@ -313,39 +313,40 @@ export default function HeaderEditMode() {
variants={ toolbarVariants }
transition={ toolbarTransition }
>
{ ! isFocusMode && hasDefaultEditorCanvasView && (
<div
className={ classnames(
'edit-site-header-edit-mode__preview-options',
{ 'is-zoomed-out': isZoomedOutView }
) }
<div
className={ classnames(
'edit-site-header-edit-mode__preview-options',
{ 'is-zoomed-out': isZoomedOutView }
) }
>
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
label={ __( 'View' ) }
isEnabled={
! isFocusMode && hasDefaultEditorCanvasView
}
>
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
label={ __( 'View' ) }
>
{ ( { onClose } ) => (
<MenuGroup>
<MenuItem
href={ homeUrl }
target="_blank"
icon={ external }
onClick={ onClose }
>
{ __( 'View site' ) }
<VisuallyHidden as="span">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</VisuallyHidden>
</MenuItem>
</MenuGroup>
) }
</PreviewOptions>
</div>
) }
{ ( { onClose } ) => (
<MenuGroup>
<MenuItem
href={ homeUrl }
target="_blank"
icon={ external }
onClick={ onClose }
>
{ __( 'View site' ) }
<VisuallyHidden as="span">
{
/* translators: accessibility text */
__( '(opens in a new tab)' )
}
</VisuallyHidden>
</MenuItem>
</MenuGroup>
) }
</PreviewOptions>
</div>
<SaveButton />
{ ! isDistractionFree && (
<PinnedItems.Slot scope="core/edit-site" />
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/e2e/specs/site-editor/style-book.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test.describe( 'Style Book', () => {
).not.toBeVisible();
await expect(
page.locator( 'role=button[name="View"i]' )
).not.toBeVisible();
).toBeDisabled();
} );

test( 'should have tabs containing block examples', async ( { page } ) => {
Expand Down

1 comment on commit 2db2dc0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 2db2dc0.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6014995047
📝 Reported issues:

Please sign in to comment.