Skip to content
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
8 changes: 8 additions & 0 deletions packages/edit-navigation/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ export const COMPLEMENTARY_AREA_SCOPE = 'core/edit-navigation';
* @type {string}
*/
export const COMPLEMENTARY_AREA_ID = 'edit-navigation/block-inspector';

/**
* The string identifier for the menu item's "target" attribute indicating
* the menu item link should open in a new tab.
*
* @type {string}
*/
export const NEW_TAB_TARGET_ATTRIBUTE = '_blank';
10 changes: 9 additions & 1 deletion packages/edit-navigation/src/store/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { parse, createBlock } from '@wordpress/blocks';
/**
* Internal dependencies
*/
import { NAVIGATION_POST_KIND, NAVIGATION_POST_POST_TYPE } from '../constants';
import {
NAVIGATION_POST_KIND,
NAVIGATION_POST_POST_TYPE,
NEW_TAB_TARGET_ATTRIBUTE,
} from '../constants';

import { resolveMenuItems, dispatch } from './controls';
import { buildNavigationPostId } from './utils';

Expand Down Expand Up @@ -147,6 +152,9 @@ function convertMenuItemToBlock( menuItem, innerBlocks = [] ) {
className: menuItem.classes.join( ' ' ),
description: menuItem.description,
rel: menuItem.xfn.join( ' ' ),
...( menuItem.target === NEW_TAB_TARGET_ATTRIBUTE && {
opensInNewTab: true,
} ),
};

return createBlock( 'core/navigation-link', attributes, innerBlocks );
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-navigation/src/store/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe( 'getNavigationPostForMenu', () => {
xfn: [],
description: '',
attr_title: '',
target: '_blank',
},
];

Expand Down Expand Up @@ -151,6 +152,7 @@ describe( 'getNavigationPostForMenu', () => {
rel: '',
description: '',
title: '',
opensInNewTab: true,
},
clientId: 'client-id-1',
innerBlocks: [],
Expand Down
4 changes: 3 additions & 1 deletion packages/edit-navigation/src/store/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe( 'computeCustomizedAttribute', () => {
{
attributes: {
label: 'wp.com',
opensInNewTab: false,
opensInNewTab: true,
url: 'http://wp.com',
className: '',
rel: '',
Expand Down Expand Up @@ -287,6 +287,7 @@ describe( 'computeCustomizedAttribute', () => {
type: 'custom',
url: 'http://wp.org',
xfn: [ 'external' ],
target: '',
},
'nav_menu_item[101]': {
_invalid: false,
Expand All @@ -302,6 +303,7 @@ describe( 'computeCustomizedAttribute', () => {
type: 'custom',
url: 'http://wp.com',
xfn: [ '' ],
target: '_blank',
},
} );
} );
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-navigation/src/store/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
isProcessingPost,
} from './controls';

import { NEW_TAB_TARGET_ATTRIBUTE } from '../constants';

/**
* Builds an ID for a new navigation post.
*
Expand Down Expand Up @@ -144,6 +146,9 @@ export function computeCustomizedAttribute(
xfn: block.attributes.rel?.split( ' ' ),
classes: block.attributes.className?.split( ' ' ),
attr_title: block.attributes.title,
target: block.attributes.opensInNewTab
? NEW_TAB_TARGET_ATTRIBUTE
: '',
};
} else {
attributes = {
Expand Down