From 3b3c7004c3f54b1a3d5403c53a4a0eba0d43708c Mon Sep 17 00:00:00 2001 From: Radoslav Stankov Date: Tue, 7 Jun 2016 18:49:26 +0300 Subject: [PATCH] Add "cancel" button This is needed because currently the form disappears when it blur-ed. --- .../common/CreateVariationButton/index.js | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/plugins/react/frontend/components/common/CreateVariationButton/index.js b/plugins/react/frontend/components/common/CreateVariationButton/index.js index 6d73f7b..7ebe04a 100644 --- a/plugins/react/frontend/components/common/CreateVariationButton/index.js +++ b/plugins/react/frontend/components/common/CreateVariationButton/index.js @@ -25,18 +25,26 @@ class CreateVariationButton extends Component { } } - onBlur = () => { + resetState() { this.setState({ + inputValue: '', + error: '', inputVisible: false, }); } - buttonClick = () => { + showForm = () => { this.setState({ inputVisible: true, }); }; + hideForm = (evt) => { + evt && evt.stopPropagation(); // eslint-disable-line no-unused-expressions + + this.resetState(); + }; + changeInput = (data) => { this.setState({ error: '', @@ -62,17 +70,14 @@ class CreateVariationButton extends Component { return; } - this.setState({ - inputValue: '', - error: '', - }); + this.resetState(); this.props.onSubmit(this.state.inputValue, slug); }; render() { return ( @@ -86,7 +91,6 @@ class CreateVariationButton extends Component { value={this.state.inputValue} onChange={this.changeInput} placeholder="Variation name" - onBlur={this.onBlur} ref={(ref) => { this.input = ref; }} /> +
{this.state.error}