Skip to content

Commit

Permalink
Buttons: allow split and merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 19, 2020
1 parent 7fa12a3 commit 894286b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '@wordpress/block-editor';
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';
import { link } from '@wordpress/icons';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -123,7 +124,14 @@ function URLPicker( {
}

function ButtonEdit( props ) {
const { attributes, setAttributes, className, isSelected } = props;
const {
attributes,
setAttributes,
className,
isSelected,
onReplace,
mergeBlocks,
} = props;
const {
borderRadius,
linkTarget,
Expand Down Expand Up @@ -183,6 +191,19 @@ function ButtonEdit( props ) {
: undefined,
...colorProps.style,
} }
onSplit={ ( value ) => {
if ( ! value ) {
return createBlock( 'core/button' );
}

return createBlock( 'core/button', {
...attributes,
text: value,
} );
} }
onReplace={ onReplace }
onMerge={ mergeBlocks }
identifier="text"
/>
</Block.div>
<URLPicker
Expand Down
3 changes: 3 additions & 0 deletions packages/block-library/src/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ export const settings = {
edit,
save,
deprecated,
merge: ( { text: textA = '' }, { text: textB = '' } ) => ( {
text: textA + textB,
} ),
};

0 comments on commit 894286b

Please sign in to comment.