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
| Prop | Type | Default | Description |
|---|---|---|---|
attributes | object | (required) | The block’s full attributes object; reads attributes.link |
setAttributes | function | (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 settinglinkto 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
| Block | Notes |
|---|---|
| Container | Entire block becomes a link; editor/frontend render as <a> when URL is set |
| Button | Individual button linking |
| Theme Button | Individual button linking |
| Fitted Image | Entire image block becomes a link (alternative to linkToPost) |