Skip to content

Commit

Permalink
Add title attribute to link block. (#24993)
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines authored Sep 2, 2020
1 parent e703aee commit ab5cbfa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
7 changes: 4 additions & 3 deletions packages/block-library/src/navigation-link/block.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"name": "core/navigation-link",
"category": "design",
"parent": [
"core/navigation"
],
"parent": [ "core/navigation" ],
"attributes": {
"label": {
"type": "string"
Expand All @@ -26,6 +24,9 @@
},
"url": {
"type": "string"
},
"title": {
"type": "string"
}
},
"usesContext": [
Expand Down
18 changes: 17 additions & 1 deletion packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -267,6 +275,14 @@ function NavigationLinkEdit( {
'The description will be displayed in the menu if the current theme supports it.'
) }
/>
<TextControl
value={ title || '' }
onChange={ ( titleValue ) => {
setAttributes( { title: titleValue } );
} }
label={ __( 'Link title' ) }
autoComplete="off"
/>
<TextControl
value={ rel || '' }
onChange={ ( relValue ) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ab5cbfa

Please sign in to comment.