MethodLinkToolbar

 
 
 
 

Overview

Block toolbar link popover with WordPress page search, URL input, and “open in new tab” toggle.

  • File: lib/blocks/components/MethodLinkToolbar.js
  • Type: Block toolbar component (renders into BlockControls)

Props

PropTypeDefaultDescription
attributesobject(required)The block’s full attributes object; reads attributes.link
setAttributesfunction(required)WordPress setAttributes function

Behavior

MethodLinkToolbar renders link management controls in the block’s floating toolbar. It has two visual states:


Unlinked State

Shows a single “Link” button (chain icon: admin-links). Clicking it opens the link popover.


Linked State

Shows two buttons:

  • Edit Link (pencil icon: edit) — opens the link popover for editing
  • Unlink (broken chain icon: editor-unlink) — clears the link by setting link to an empty object

Link Popover

Uses WordPress’s native LinkControl inside a Popover, providing:

  • URL text input
  • Page/post search (via searchInputPlaceholder: "Search pages...")
  • “Open in new tab” toggle
  • Closes when clicking outside the popover

Attribute Shape

The component reads and writes attributes.link:

JSON
{
  url: 'https://example.com/page',
  opensInNewTab: false,
  rel: '',
}

When unlinked, link is set to {} (empty object). Consuming blocks check attributes.link?.url to determine whether to render as an <a> or <div>.


Usage by Blocks

BlockNotes
ContainerEntire block becomes a link; editor/frontend render as <a> when URL is set
ButtonIndividual button linking
Theme ButtonIndividual button linking
Fitted ImageEntire image block becomes a link (alternative to linkToPost)