Skip to content
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
38 changes: 24 additions & 14 deletions packages/block-library/src/navigation/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
useBlockProps,
RecursionProvider,
useHasRecursion,
privateApis as blockEditorPrivateApis,
store as blockEditorStore,
withColors,
ContrastChecker,
Expand Down Expand Up @@ -85,6 +86,8 @@ import {
NAVIGATION_OVERLAY_TEMPLATE_PART_AREA,
} from '../constants';

const { isIsolatedEditorKey } = unlock( blockEditorPrivateApis );

/**
* Component that renders the Add page button for the Navigation block.
*
Expand Down Expand Up @@ -319,19 +322,25 @@ function Navigation( {

// Skip recursion check when in preview mode.
const recursionDetected = useHasRecursion( recursionId );
const { isPreviewMode, onNavigateToEntityRecord, currentTheme } = useSelect(
( select ) => {
const { getSettings } = select( blockEditorStore );
const settings = getSettings();
return {
isPreviewMode: settings.isPreviewMode,
onNavigateToEntityRecord: settings?.onNavigateToEntityRecord,
// Needed to construct the template part ID for the overlay preview.
currentTheme: select( coreStore ).getCurrentTheme()?.stylesheet,
};
},
[]
);
const {
isPreviewMode,
onNavigateToEntityRecord,
currentTheme,
editorDisabledResponsive,
} = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const settings = getSettings();
return {
isPreviewMode: settings.isPreviewMode,
onNavigateToEntityRecord: settings?.onNavigateToEntityRecord,
// Needed to construct the template part ID for the overlay preview.
currentTheme: select( coreStore ).getCurrentTheme()?.stylesheet,
// In preview mode or isolated editor, always show navigation expanded (no hamburger)
// so users can see and interact with all menu items.
editorDisabledResponsive:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think its better to only return what we need from the selector and do calculations outside it, in which case I think it would be preferable to return isIsolatedEditor here and then make editorDisabledResponsive a const in the component. I could be wrong though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had figured to only export from the selector what you actually need. I think it would cause fewer updates if we do the calculation within the selector. It's minor either way in this case though. I'd opt to leave it as is.

settings.isPreviewMode || !! settings?.[ isIsolatedEditorKey ],
};
}, [] );
const hasAlreadyRendered = isPreviewMode ? false : recursionDetected;

const blockEditingMode = useBlockEditingMode();
Expand Down Expand Up @@ -603,7 +612,8 @@ function Navigation( {
setAttributes,
] );

const isResponsive = 'never' !== overlayMenu;
const isResponsive = 'never' !== overlayMenu && ! editorDisabledResponsive;

const blockProps = useBlockProps( {
ref: navRef,
className: clsx(
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ function VisualEditor( {
: ''
}${
isNavigationPreview
? `.block-editor-iframe__body{${ centerContentCSS }}`
? `.block-editor-iframe__body{${ centerContentCSS }padding:var(--wp--style--block-gap,2em);}`
: ''
}`,
// The CSS for enableResizing centers the body content vertically when resizing is enabled and applies a background
Expand Down
Loading