@@ -32,7 +32,8 @@ MultiSelect.defaultProps = {
32
32
}
33
33
] ,
34
34
customValue : false ,
35
- chipAlternateText : 'Item Selected'
35
+ chipAlternateText : 'Item Selected' ,
36
+ closeOnSelect : true
36
37
}
37
38
38
39
function MultiSelect ( {
@@ -58,7 +59,8 @@ function MultiSelect({
58
59
customValue,
59
60
onMenuOpen,
60
61
onMenuClose,
61
- chipAlternateText
62
+ chipAlternateText,
63
+ closeOnSelect
62
64
} ) {
63
65
const [ value , setValue ] = useState ( [ ] )
64
66
const [ options , setOptions ] = useState ( userOptions || [ ] )
@@ -148,6 +150,8 @@ function MultiSelect({
148
150
}
149
151
150
152
setValue ( preDefinedValue )
153
+ // close on option select
154
+ closeOnSelect && setMenuOpen ( false )
151
155
} , [ defaultValue ] )
152
156
153
157
const setNewValue = ( val ) => {
@@ -172,7 +176,6 @@ function MultiSelect({
172
176
}
173
177
return { label, value }
174
178
}
175
-
176
179
const addValue = ( newValObj ) => {
177
180
let tmp = [ ...value ]
178
181
if ( singleSelect ) {
@@ -328,7 +331,7 @@ function MultiSelect({
328
331
}
329
332
}
330
333
331
- const notClickableItem = ( target ) => {
334
+ const nonClickableItem = ( target ) => {
332
335
if (
333
336
target . hasAttribute ( 'clickable' ) ||
334
337
target . parentNode . hasAttribute ( 'clickable' ) ||
@@ -357,7 +360,7 @@ function MultiSelect({
357
360
}
358
361
359
362
const openMenu = ( { target } ) => {
360
- if ( notClickableItem ( target ) ) {
363
+ if ( nonClickableItem ( target ) ) {
361
364
if ( checkIsDropdownHandle ( target ) ) {
362
365
if ( ! menuOpen ) {
363
366
setMenuOpen ( true )
@@ -420,22 +423,14 @@ function MultiSelect({
420
423
/>
421
424
) ) }
422
425
{ ! singleSelect && disableChip && value . length > 0 && (
423
- < span
424
- className = 'msl-single-value'
425
- data-msl
426
- style = { { width : calculatedWidth } }
427
- >
426
+ < span className = 'msl-single-value' data-msl >
428
427
{ value . length === 1
429
428
? showLabel ( value [ 0 ] )
430
429
: `${ value . length } ${ chipAlternateText } ` }
431
430
</ span >
432
431
) }
433
432
{ singleSelect && value . length === 1 && (
434
- < span
435
- className = 'msl-single-value'
436
- data-msl
437
- style = { { width : calculatedWidth } }
438
- >
433
+ < span className = 'msl-single-value' data-msl >
439
434
{ showLabel ( value [ 0 ] ) }
440
435
</ span >
441
436
) }
0 commit comments