From d10c5ed39f1fbdf34000458544d35a6fc4e3db8e Mon Sep 17 00:00:00 2001 From: Ales N Date: Thu, 23 Jul 2015 11:40:04 +0200 Subject: [PATCH] Updating Select's props.placeholder doesn't get reflected by the component - fix for this bug When Select receives updated 'placeholder' in its props, the Select component would not reflect it. The initial placeholder would remain displayed. This code change fixes this bug --- src/Select.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Select.js b/src/Select.js index 3a31228189..cd10c4982e 100644 --- a/src/Select.js +++ b/src/Select.js @@ -157,8 +157,8 @@ var Select = React.createClass({ filteredOptions: this.filterOptions(newProps.options) }); } - if (newProps.value !== this.state.value) { - this.setState(this.getStateFromValue(newProps.value, newProps.options)); + if (newProps.value !== this.state.value || newProps.placeholder !== this.state.placeholder) { + this.setState(this.getStateFromValue(newProps.value, newProps.options, newProps.placeholder)); } }, @@ -201,10 +201,13 @@ var Select = React.createClass({ return true; }, - getStateFromValue: function(value, options) { + getStateFromValue: function(value, options, placeholder) { if (!options) { options = this.state.options; } + if (!placeholder) { + placeholder = this.props.placeholder; + } // reset internal filter string this._optionsFilterString = ''; @@ -217,7 +220,7 @@ var Select = React.createClass({ values: values, inputValue: '', filteredOptions: filteredOptions, - placeholder: !this.props.multi && values.length ? values[0].label : this.props.placeholder, + placeholder: !this.props.multi && values.length ? values[0].label : placeholder, focusedOption: !this.props.multi && values.length ? values[0] : filteredOptions[0] }; },