Skip to content
Merged
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
37 changes: 26 additions & 11 deletions packages/block-library/src/navigation-link/link-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function UnforwardedLinkUI( props, ref ) {
const [ addingPage, setAddingPage ] = useState( false );
const [ focusAddBlockButton, setFocusAddBlockButton ] = useState( false );
const [ focusAddPageButton, setFocusAddPageButton ] = useState( false );
const { canCreate: canCreatePage } = useResourcePermissions( {
const permissions = useResourcePermissions( {
kind: 'postType',
name: postType,
} );
Expand Down Expand Up @@ -142,8 +142,13 @@ function UnforwardedLinkUI( props, ref ) {
onChange={ props.onChange }
onRemove={ props.onRemove }
onCancel={ props.onCancel }
renderControlBottom={ () =>
! link?.url?.length && (
renderControlBottom={ () => {
// Don't show the tools when there is submitted link (preview state).
if ( link?.url?.length ) {
return null;
}

return (
<LinkUITools
focusAddBlockButton={ focusAddBlockButton }
focusAddPageButton={ focusAddPageButton }
Expand All @@ -155,11 +160,16 @@ function UnforwardedLinkUI( props, ref ) {
setAddingPage( true );
setFocusAddPageButton( false );
} }
blockEditingMode={ blockEditingMode }
canCreatePage={ canCreatePage }
canAddPage={
permissions?.canCreate &&
type === 'page'
}
canAddBlock={
blockEditingMode === 'default'
}
/>
)
}
);
} }
/>
</div>
) }
Expand Down Expand Up @@ -199,8 +209,8 @@ const LinkUITools = ( {
setAddingPage,
focusAddBlockButton,
focusAddPageButton,
canCreatePage,
blockEditingMode,
canAddPage,
Copy link
Contributor

@scruffian scruffian Sep 5, 2025

Choose a reason for hiding this comment

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

Why change the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consistency with the other one and to distinguish it from the idea of permissions being the only thing that that is regulating the display.

canAddBlock,
} ) => {
const blockInserterAriaRole = 'listbox';
const addBlockButtonRef = useRef();
Expand All @@ -220,9 +230,14 @@ const LinkUITools = ( {
}
}, [ focusAddPageButton ] );

// Don't render anything if neither button should be shown
if ( ! canAddPage && ! canAddBlock ) {
return null;
}

return (
<VStack spacing={ 0 } className="link-ui-tools">
{ canCreatePage && (
{ canAddPage && (
<Button
__next40pxDefaultSize
ref={ addPageButtonRef }
Expand All @@ -236,7 +251,7 @@ const LinkUITools = ( {
{ __( 'Create page' ) }
</Button>
) }
{ blockEditingMode === 'default' && (
{ canAddBlock && (
<Button
__next40pxDefaultSize
ref={ addBlockButtonRef }
Expand Down
Loading