@@ -183,15 +183,33 @@ class Picker extends BaseComponent {
183
183
return items ;
184
184
}
185
185
186
- getLabel ( ) {
187
- const { value} = this . state ;
188
- const { getLabel, getItemLabel} = this . props ;
186
+ shouldNotChangePickerLabelWhileSelecting = ( ) => {
187
+ const { mode} = this . props ;
188
+ return mode === Picker . modes . MULTI ;
189
+ }
190
+
191
+ getLabelValueText = ( ) => {
192
+ const { value : propsValue } = this . props ;
193
+ const { value : stateValue } = this . props ;
194
+ if ( this . shouldNotChangePickerLabelWhileSelecting ( ) ) {
195
+ return this . getLabel ( propsValue ) ;
196
+ }
197
+ return this . getLabel ( stateValue ) ;
198
+ }
199
+
200
+ getLabelsFromArray = ( value ) => {
201
+ const { getItemLabel} = this . props ;
202
+ return _ . chain ( value )
203
+ . map ( getItemLabel || 'label' )
204
+ . join ( ', ' )
205
+ . value ( ) ;
206
+ } ;
207
+
208
+ getLabel ( value ) {
209
+ const { getLabel} = this . props ;
189
210
190
211
if ( _ . isArray ( value ) ) {
191
- return _ . chain ( value )
192
- . map ( getItemLabel || 'label' )
193
- . join ( ', ' )
194
- . value ( ) ;
212
+ return this . getLabelsFromArray ( value ) ;
195
213
}
196
214
197
215
if ( _ . isFunction ( getLabel ) ) {
@@ -206,7 +224,7 @@ class Picker extends BaseComponent {
206
224
const { items} = this . state ;
207
225
const selectedItem = _ . find ( items , { value} ) ;
208
226
return _ . get ( selectedItem , 'label' ) ;
209
- }
227
+ } ;
210
228
211
229
handlePickerOnPress = ( ) => {
212
230
this . toggleExpandableModal ( true ) ;
@@ -260,7 +278,7 @@ class Picker extends BaseComponent {
260
278
261
279
clearSearchField = ( ) => {
262
280
this . setState ( { searchValue : '' } ) ;
263
- }
281
+ } ;
264
282
265
283
appendPropsToChildren = ( ) => {
266
284
const { children, mode, getItemValue, getItemLabel, showSearch, renderItem} = this . props ;
@@ -301,17 +319,18 @@ class Picker extends BaseComponent {
301
319
listProps,
302
320
testID
303
321
} = this . getThemeProps ( ) ;
304
- const { showExpandableModal, selectedItemPosition} = this . state ;
322
+ const { showExpandableModal, selectedItemPosition, value } = this . state ;
305
323
const children = this . appendPropsToChildren ( this . props . children ) ;
306
324
307
325
if ( renderCustomModal ) {
308
326
const modalProps = {
309
327
visible : showExpandableModal ,
310
328
toggleModal : this . toggleExpandableModal ,
311
329
onSearchChange : this . onSearchChange ,
312
- children
330
+ children,
331
+ onDone : ( ) => this . onDoneSelecting ( value ) ,
332
+ onCancel : this . cancelSelect
313
333
} ;
314
-
315
334
return renderCustomModal ( modalProps ) ;
316
335
}
317
336
@@ -324,7 +343,7 @@ class Picker extends BaseComponent {
324
343
topBarProps = { {
325
344
...topBarProps ,
326
345
onCancel : this . cancelSelect ,
327
- onDone : mode === Picker . modes . MULTI ? ( ) => this . onDoneSelecting ( this . state . value ) : undefined
346
+ onDone : mode === Picker . modes . MULTI ? ( ) => this . onDoneSelecting ( value ) : undefined
328
347
} }
329
348
showSearch = { showSearch }
330
349
searchStyle = { searchStyle }
@@ -358,7 +377,7 @@ class Picker extends BaseComponent {
358
377
}
359
378
360
379
const textInputProps = TextField . extractOwnProps ( this . getThemeProps ( ) ) ;
361
- const label = this . getLabel ( ) ;
380
+ const label = this . getLabelValueText ( ) ;
362
381
return (
363
382
< TextField
364
383
{ ...textInputProps }
0 commit comments