From a3881dae7f97a62138734f398fa4754e38159988 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Wed, 2 Sep 2020 11:20:59 +1000 Subject: [PATCH] Add title attribute to link block. --- .../src/navigation-link/block.json | 7 ++++--- .../block-library/src/navigation-link/edit.js | 18 +++++++++++++++++- .../src/navigation-link/index.php | 5 ++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/block-library/src/navigation-link/block.json b/packages/block-library/src/navigation-link/block.json index a4dba26451c54..edad7abb6cda7 100644 --- a/packages/block-library/src/navigation-link/block.json +++ b/packages/block-library/src/navigation-link/block.json @@ -1,9 +1,7 @@ { "name": "core/navigation-link", "category": "design", - "parent": [ - "core/navigation" - ], + "parent": [ "core/navigation" ], "attributes": { "label": { "type": "string" @@ -26,6 +24,9 @@ }, "url": { "type": "string" + }, + "title": { + "type": "string" } }, "usesContext": [ diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index 706bfc43f79a0..a24175721ba9f 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -139,7 +139,15 @@ function NavigationLinkEdit( { mergeBlocks, onReplace, } ) { - const { label, type, opensInNewTab, url, description, rel } = attributes; + const { + label, + type, + opensInNewTab, + url, + description, + rel, + title, + } = attributes; const link = { url, opensInNewTab, @@ -267,6 +275,14 @@ function NavigationLinkEdit( { 'The description will be displayed in the menu if the current theme supports it.' ) } /> + { + setAttributes( { title: titleValue } ); + } } + label={ __( 'Link title' ) } + autoComplete="off" + /> { diff --git a/packages/block-library/src/navigation-link/index.php b/packages/block-library/src/navigation-link/index.php index ae28e42184858..ec08adbb09795 100644 --- a/packages/block-library/src/navigation-link/index.php +++ b/packages/block-library/src/navigation-link/index.php @@ -140,13 +140,16 @@ function render_block_core_navigation_link( $attributes, $content, $block ) { $html .= ' target="_blank" '; } - // Start appending HTML attributes to anchor tag. if ( isset( $attributes['rel'] ) ) { $html .= ' rel="' . esc_attr( $attributes['rel'] ) . '"'; } elseif ( isset( $attributes['nofollow'] ) && $attributes['nofollow'] ) { $html .= ' rel="nofollow"'; } + if ( isset( $attributes['title'] ) ) { + $html .= ' title="' . esc_attr( $attributes['title'] ) . '"'; + } + // End appending HTML attributes to anchor tag. // Start anchor tag content.