Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title attribute to Navigation Link block. #24993

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
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
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