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
9 changes: 7 additions & 2 deletions packages/block-library/src/navigation-link/link-ui/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getSuggestionsQuery( type, kind ) {
}

function UnforwardedLinkUI( props, ref ) {
const { label, url, opensInNewTab, type, kind, id } = props.link;
const { label, url, opensInNewTab, type, kind, id, metadata } = props.link;
const postType = type || 'page';

const [ addingBlock, setAddingBlock ] = useState( false );
Expand All @@ -78,6 +78,11 @@ function UnforwardedLinkUI( props, ref ) {
name: postType,
} );

// Check if there's a URL binding with the core/entity source
// Only enable handleEntities when there's actually a binding present
const hasUrlBinding =
metadata?.bindings?.url?.source === 'core/entity' && !! id;

// Memoize link value to avoid overriding the LinkControl's internal state.
// This is a temporary fix. See https://github.com/WordPress/gutenberg/issues/50976#issuecomment-1568226407.
const link = useMemo(
Expand Down Expand Up @@ -145,7 +150,7 @@ function UnforwardedLinkUI( props, ref ) {
onChange={ props.onChange }
onRemove={ props.onRemove }
onCancel={ props.onCancel }
handleEntities
handleEntities={ hasUrlBinding }
renderControlBottom={ () => {
// Don't show the tools when there is submitted link (preview state).
if ( link?.url?.length ) {
Expand Down
53 changes: 53 additions & 0 deletions test/e2e/specs/editor/blocks/navigation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,59 @@ test.describe( 'Navigation block', () => {
await expect( linkInput ).toBeEnabled();
await expect( linkInput ).toHaveValue( '' );
} );

test( 'existing links with id but no binding remain editable', async ( {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed this test doesn't actually open Link UI. I think we need to augment BOTH tests in this describe otherwise our coverage is limited 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow up Issue #72204

editor,
page,
admin,
navigation,
requestUtils,
} ) => {
await admin.createNewPost();

// Create a menu with an existing link that has id but no binding
// This simulates existing sites before the binding feature
const menu = await requestUtils.createNavigationMenu( {
title: 'Test Menu',
content: `<!-- wp:navigation-link {"label":"Support","type":"page","id":${ testPage1.id },"url":"${ testPage1.link }","kind":"post-type"} /-->`,
} );

await editor.insertBlock( {
name: 'core/navigation',
attributes: {
ref: menu.id,
},
} );

// Select the Navigation Link block
const navBlock = navigation.getNavBlock();
await editor.selectBlocks( navBlock );

const navLinkBlock = navBlock
.getByRole( 'document', {
name: 'Block: Page Link',
} )
.first();

await editor.selectBlocks( navLinkBlock );

// Check the Inspector controls for the Nav Link block
// to verify the Link field is enabled (not locked in entity mode)
await editor.openDocumentSettingsSidebar();
const settingsControls = page
.getByRole( 'region', { name: 'Editor settings' } )
.getByRole( 'tabpanel', { name: 'Settings' } );

await expect( settingsControls ).toBeVisible();

const linkInput = settingsControls.getByRole( 'textbox', {
name: 'Link',
} );

// For existing links with id but no binding, the input should be enabled
await expect( linkInput ).toBeEnabled();
await expect( linkInput ).toHaveValue( testPage1.link );
} );
} );
} );

Expand Down
Loading