Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
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
37 changes: 25 additions & 12 deletions packages/edit-site/src/components/header-edit-mode/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import { PinnedItems } from '@wordpress/interface';
import { _x, __ } from '@wordpress/i18n';
import { listView, plus, external, chevronUpDown } from '@wordpress/icons';
import {
desktop,
listView,
plus,
external,
chevronUpDown,
} from '@wordpress/icons';
import {
__unstableMotion as motion,
Button,
Expand All @@ -45,6 +51,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 +163,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,13 +319,13 @@ 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 }
) }
>
{ ! isFocusMode && hasDefaultEditorCanvasView ? (
<PreviewOptions
deviceType={ deviceType }
setDeviceType={ setPreviewDeviceType }
Copy link
Member

@Mamaduka Mamaduka Aug 29, 2023

Choose a reason for hiding this comment

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

The PreviewOptions component has an isEnabled prop that can handle this state for us. You don't need to render components conditionally.

Side note: Disabling the toggle doesn't match a11y best practices, but that's a matter of general component improvement and shouldn't be a blocker here.

Expand All @@ -344,8 +350,15 @@ export default function HeaderEditMode() {
</MenuGroup>
) }
</PreviewOptions>
</div>
) }
) : (
<Button
label={ __( 'View' ) }
icon={ desktop }
disabled
__experimentalIsFocusable
/>
) }
</div>
<SaveButton />
{ ! isDistractionFree && (
<PinnedItems.Slot scope="core/edit-site" />
Expand Down