File tree Expand file tree Collapse file tree 1 file changed +16
-14
lines changed Expand file tree Collapse file tree 1 file changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -182,20 +182,22 @@ class Picker extends Component {
182
182
}
183
183
184
184
static getDerivedStateFromProps ( nextProps , prevState ) {
185
- if ( ! _ . isEmpty ( nextProps . value ) && prevState . value !== nextProps . value ) {
186
- if ( prevState . prevValue !== prevState . value ) {
187
- // for this.setState() updates to 'value'
188
- // NOTE: this.setState() already updated the 'value' so here we only updating the 'prevValue'
189
- return {
190
- prevValue : prevState . value
191
- } ;
192
- } else {
193
- // for prop update to 'value'
194
- return {
195
- value : nextProps . value
196
- } ;
197
- }
198
- } else if ( _ . isFunction ( nextProps . renderPicker ) && prevState . value !== nextProps . value ) {
185
+ const hasNextValue = ! _ . isEmpty ( nextProps . value ) || _ . isNumber ( nextProps . value ) ;
186
+ /* Relevant for keeping the value prop controlled - react when user change value prop */
187
+ const externalValueChanged = hasNextValue && prevState . value !== nextProps . value ;
188
+ /* Relevant for multi select mode when we keep an internal value state */
189
+ const internalValueChanged = prevState . value !== prevState . prevValue ;
190
+ if ( internalValueChanged && nextProps . mode === Picker . modes . MULTI ) {
191
+ /* for this.setState() updates to 'value'
192
+ NOTE: this.setState() already updated the 'value' so here we only updating the 'prevValue' */
193
+ return {
194
+ prevValue : prevState . value
195
+ } ;
196
+ } else if ( externalValueChanged ) {
197
+ return {
198
+ value : nextProps . value
199
+ } ;
200
+ } else if ( _ . isFunction ( nextProps . renderPicker ) && externalValueChanged ) {
199
201
return {
200
202
prevValue : prevState . value ,
201
203
value : nextProps . value
You can’t perform that action at this time.
0 commit comments