1- import React , { useState } from 'react' ;
1+ import React , { useState } from 'react' ;
22import './styles.scss' ;
33import IconTooltip from '../IconTooltip' ;
4- import { IconButton , TooltipProps } from '@mui/material' ;
4+ import { IconButton , TooltipProps } from '@mui/material' ;
55import Icon from '../Icon/Icon' ;
6- import PillList , { PillListItem } from '../PillList' ;
6+ import PillList , { PillListItem } from '../PillList' ;
77
88export type MultiSelectProps < K , V > = {
99 className ?: string ;
@@ -22,6 +22,7 @@ export type MultiSelectProps<K, V> = {
2222 selectedOptions : K [ ] ;
2323 tooltipTitle ?: TooltipProps [ 'title' ] ;
2424 disabled ?: boolean ;
25+ onBlur ?: ( ) => void ;
2526} ;
2627
2728export default function MultiSelect < K , V > ( props : MultiSelectProps < K , V > ) : JSX . Element {
@@ -50,20 +51,25 @@ export default function MultiSelect<K, V>(props: MultiSelectProps<K, V>): JSX.El
5051 setOpenedOptions ( ( isOpen ) => ! isOpen && ! disabled ) ;
5152 } ;
5253
53- const closeOptions = ( ) => {
54+ const onBlurHandler = ( ) => {
5455 setOpenedOptions ( false ) ;
56+ if ( props . onBlur ) {
57+ props . onBlur ( ) ;
58+ }
5559 } ;
5660
5761 const unselectedOptions = Array . from < K > ( options . keys ( ) ) . filter ( ( key : K ) => ! selectedOptions . includes ( key ) ) ;
5862
59- const valuesPillData = selectedOptions . map ( ( item ) => {
60- const value = options . get ( item ) ;
63+ const valuesPillData = selectedOptions
64+ . map ( ( item ) => {
65+ const value = options . get ( item ) ;
6166
62- return {
63- id : item ,
64- value : value ? valueRenderer ( value ) : ( missingValuePlaceholder || '' ) ,
65- } ;
66- } ) . filter ( ( data ) => data . value ) as PillListItem < K > [ ] ;
67+ return {
68+ id : item ,
69+ value : value ? valueRenderer ( value ) : missingValuePlaceholder || '' ,
70+ } ;
71+ } )
72+ . filter ( ( data ) => data . value ) as PillListItem < K > [ ] ;
6773
6874 return (
6975 < div className = { `multi-select ${ className } ` } >
@@ -72,26 +78,15 @@ export default function MultiSelect<K, V>(props: MultiSelectProps<K, V>): JSX.El
7278 { label } { tooltipTitle && < IconTooltip title = { tooltipTitle } /> }
7379 </ label >
7480 ) }
75- < div
76- className = { `multi-select__container ${ fullWidth ? 'multi-select__container--fullWidth' : '' } ` }
77- onBlur = { closeOptions }
78- tabIndex = { 0 }
79- >
81+ < div className = { `multi-select__container ${ fullWidth ? 'multi-select__container--fullWidth' : '' } ` } onBlur = { onBlurHandler } tabIndex = { 0 } >
8082 < div id = { id } className = { `multi-select__values${ disabled ? '--disabled' : '' } ` } onClick = { toggleOptions } >
81- { selectedOptions . length > 0
82- ? ( < PillList
83- data = { valuesPillData }
84- onRemove = { onRemove }
85- onClick = { onPillClick }
86- className = { pillListClassName }
87- /> )
88- : ( < p className = 'multi-select__placeholder-text' > { placeHolder } </ p > )
89- }
83+ { selectedOptions . length > 0 ? (
84+ < PillList data = { valuesPillData } onRemove = { onRemove } onClick = { onPillClick } className = { pillListClassName } />
85+ ) : (
86+ < p className = 'multi-select__placeholder-text' > { placeHolder } </ p >
87+ ) }
9088 < div className = { 'multi-select__values__icon-button' } aria-label = 'show-options' >
91- < Icon
92- name = { openedOptions ? 'chevronUp' : 'chevronDown' }
93- className = { `multi-select__values__icon-right${ disabled ? '--disabled' : '' } ` }
94- />
89+ < Icon name = { openedOptions ? 'chevronUp' : 'chevronDown' } className = { `multi-select__values__icon-right${ disabled ? '--disabled' : '' } ` } />
9590 </ div >
9691 </ div >
9792 { options && unselectedOptions . length > 0 && openedOptions && (
@@ -101,9 +96,9 @@ export default function MultiSelect<K, V>(props: MultiSelectProps<K, V>): JSX.El
10196 const optionValue = options . get ( optionKey ) ;
10297
10398 return (
104- < li key = { index } className = 'select-value' onClick = { ( ) => onAdd ( optionKey ) } > {
105- optionValue ? valueRenderer ( optionValue ) : ( missingValuePlaceholder || '' )
106- } </ li >
99+ < li key = { index } className = 'select-value' onClick = { ( ) => onAdd ( optionKey ) } >
100+ { optionValue ? valueRenderer ( optionValue ) : missingValuePlaceholder || '' }
101+ </ li >
107102 ) ;
108103 } ) }
109104 </ ul >
0 commit comments