From e08af7b7ad8cefba9dd5bfc92a48296ef32d4d3f Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 21 Aug 2018 14:53:21 +0200 Subject: [PATCH] Format toolbar: Improve derived state handling --- .../src/components/rich-text/format-toolbar/index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/editor/src/components/rich-text/format-toolbar/index.js b/packages/editor/src/components/rich-text/format-toolbar/index.js index 93a354a93e15c..a45da33e91076 100644 --- a/packages/editor/src/components/rich-text/format-toolbar/index.js +++ b/packages/editor/src/components/rich-text/format-toolbar/index.js @@ -1,3 +1,8 @@ +/** + * External dependencies + */ +import { get } from 'lodash'; + /** * WordPress dependencies */ @@ -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' ], '' ), }; } @@ -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 ) { @@ -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' ); }