Skip to content

Commit

Permalink
Format toolbar: Improve derived state handling
Browse files Browse the repository at this point in the history
  • Loading branch information
gziolo committed Aug 21, 2018
1 parent 446fc7e commit e08af7b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/editor/src/components/rich-text/format-toolbar/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -28,7 +33,7 @@ function computeDerivedState( props ) {
selectedNodeId: props.selectedNodeId,
settingsVisible: false,
opensInNewWindow: !! props.formats.link && !! props.formats.link.target,
linkValue: '',
linkValue: get( props, [ 'formats', 'link', 'value' ], '' ),
};
}

Expand Down Expand Up @@ -102,19 +107,16 @@ class FormatToolbar extends Component {
}

addLink() {
this.setState( { linkValue: '' } );
this.props.onChange( { link: { isAdding: true } } );
}

dropLink() {
this.props.onChange( { link: null } );
this.setState( { linkValue: '' } );
}

editLink( event ) {
event.preventDefault();
this.props.onChange( { link: { ...this.props.formats.link, isAdding: true } } );
this.setState( { linkValue: this.props.formats.link.value } );
}

submitLink( event ) {
Expand All @@ -127,7 +129,6 @@ class FormatToolbar extends Component {
value,
} } );

this.setState( { linkValue: value } );
if ( ! this.props.formats.link.value ) {
this.props.speak( __( 'Link added.' ), 'assertive' );
}
Expand Down

0 comments on commit e08af7b

Please sign in to comment.