Skip to content

Commit

Permalink
Add RichText split/merge/remove to Navigation Links.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed May 22, 2020
1 parent 316c2f9 commit 6e8ea2e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
11 changes: 11 additions & 0 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function NavigationLinkEdit( {
saveEntityRecord,
selectedBlockHasDescendants,
userCanCreatePages = false,
insertBlocksAfter,
mergeBlocks,
onReplace,
} ) {
const { label, opensInNewTab, url, nofollow, description } = attributes;
const link = {
Expand Down Expand Up @@ -221,11 +224,19 @@ function NavigationLinkEdit( {
<div className="wp-block-navigation-link__content">
<RichText
ref={ ref }
identifier="label"
className="wp-block-navigation-link__label"
value={ label }
onChange={ ( labelValue ) =>
setAttributes( { label: labelValue } )
}
onMerge={ mergeBlocks }
onReplace={ onReplace }
__unstableOnSplitAtEnd={ () =>
insertBlocksAfter(
createBlock( 'core/navigation-link' )
)
}
placeholder={ itemLabelPlaceholder }
keepPlaceholderOnFocus
withoutInteractiveFormatting
Expand Down
11 changes: 7 additions & 4 deletions packages/block-library/src/navigation-link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@ import edit from './edit';
import save from './save';

const { name } = metadata;

export { metadata, name };

export const settings = {
title: __( 'Navigation Link' ),

icon,

description: __( 'Add a page, link, or another item to your navigation.' ),

__experimentalLabel: ( { label } ) => label,

merge( leftAttributes, { label: rightLabel = '' } ) {
return {
...leftAttributes,
label: leftAttributes.label + rightLabel,
};
},
edit,
save,
};

0 comments on commit 6e8ea2e

Please sign in to comment.