Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Hide 'Add block' control when Navigation Link block is in contentOnly…
… mode

- Import useBlockEditingMode hook from @wordpress/block-editor
- Check if block is in contentOnly mode using useBlockEditingMode()
- Conditionally render LinkUITools only when not in contentOnly mode
- Improves UX by hiding non-content UI when appropriate
  • Loading branch information
getdave committed Sep 3, 2025
commit 3f09ea7208bbb897c21c9c191c5f051f6683c025
8 changes: 7 additions & 1 deletion packages/block-library/src/navigation-link/link-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
LinkControl,
store as blockEditorStore,
privateApis as blockEditorPrivateApis,
useBlockEditingMode,
} from '@wordpress/block-editor';
import {
createInterpolateElement,
Expand Down Expand Up @@ -157,6 +158,10 @@ function UnforwardedLinkUI( props, ref ) {
name: postType,
} );

// Check if we're in contentOnly mode
const blockEditingMode = useBlockEditingMode();
const isContentOnlyMode = blockEditingMode === 'contentOnly';
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice in some of the other blocks we're doing a truthy check for === 'default' when showing controls, rather than an "not contentOnly", e.g. in the post title block. Would that be a better fit here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could we just extract a shared hook, useIsContentOnlyMode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andrewserong I've adjusted. It's probably a better check because it's more about allowing certain functionality only in default editing mode rather than restricting it for contentOnly.


async function handleCreate( pageTitle ) {
const page = await saveEntityRecord( 'postType', postType, {
title: pageTitle,
Expand Down Expand Up @@ -261,7 +266,8 @@ function UnforwardedLinkUI( props, ref ) {
onRemove={ props.onRemove }
onCancel={ props.onCancel }
renderControlBottom={ () =>
! link?.url?.length && (
! link?.url?.length &&
! isContentOnlyMode && (
<LinkUITools
focusAddBlockButton={ focusAddBlockButton }
setAddingBlock={ () => {
Expand Down