11import React , { MouseEvent , useEffect , useMemo , useRef , useState } from "react" ;
22import DownArrow from "../../assets/DropdownArrow.svg" ;
3- import CheckMark from "../../assets/CheckBox.svg" ;
43import SearchComponent from "./searchComponent" ;
54import { MultiSelectPropType , OptionType } from "./types" ;
65import { DEFAULT_PLACEHOLDER , Elements } from "./constants" ;
6+ import { renderAsImage } from "./utils/utils" ;
77import classes from "./styles.module.scss" ;
88import Chips from "./chips" ;
99import MenuListing from "./menuItems" ;
@@ -28,11 +28,12 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
2828 icons = { } ,
2929 onSearch = undefined ,
3030 onItemClick = undefined ,
31- setSelectedValues = undefined
31+ setSelectedValues = undefined ,
32+ clearSearchClick = undefined
3233 } = props ;
3334
34- const { Checked = CheckMark , Search, ChipClose, Arrow } = icons ;
35-
35+ const { Checked, Search, ChipClose, Arrow, ClearSearch } = icons ;
36+ const arrowIcon = Arrow ;
3637 // to show/hide div containing the checkboxes
3738 const [ isModalVisible , setIsModalVisible ] = useState < boolean > ( false ) ;
3839 const [ list , setList ] = useState < OptionType [ ] > ( [ ] ) ;
@@ -55,7 +56,7 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
5556 } , [ options ] ) ;
5657
5758 useEffect ( ( ) => {
58- if ( typeof document !== undefined ) {
59+ if ( typeof document !== ' undefined' ) {
5960 document . addEventListener ( "mouseup" , onMouseUp ) ;
6061 return ( ) => document . removeEventListener ( "mouseup" , onMouseUp ) ;
6162 }
@@ -131,15 +132,18 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
131132 [ options , selectedIds ]
132133 ) ;
133134
135+ const onClick = ( ) : void => {
136+ setShowAllChips ( true ) ;
137+ setIsModalVisible ( true ) ;
138+ }
139+
134140 return (
135141 < div className = { classes . container } style = { styles [ Elements . Container ] } >
136142 < div
137143 className = { `${ classes . box } ${ hasError && classes . errorBorder } ` }
138144 ref = { intractableAreaRef }
139145 style = { styles [ Elements . InputBox ] }
140- onClick = { ( ) : void => {
141- setShowAllChips ( true ) ;
142- } }
146+ onClick = { onClick }
143147 role = "presentation"
144148 >
145149 < div className = { classes . headSection } >
@@ -161,11 +165,12 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
161165 onFocus = { triggerModalOpen }
162166 ref = { inputRef }
163167 icon = { Search }
168+ onCloseClick = { clearSearchClick }
169+ closeIcon = { ClearSearch }
164170 />
165171 ) }
166172 { hideSearch && ! selectedIds . length && (
167- // same style for the search box is used
168- < div style = { styles [ Elements . SearchComponent ] } > { placeholder } </ div >
173+ < div className = { `${ classes . searchInput } ${ classes . label } ` } > { placeholder } </ div >
169174 ) }
170175 </ div >
171176 < button
@@ -174,14 +179,16 @@ const MultiSelect = (props: MultiSelectPropType): JSX.Element => {
174179 onClick = { ( e : MouseEvent < HTMLButtonElement > ) : void => onArrowClick ( e ) }
175180 id = "down-arrow"
176181 >
177- < img
178- src = { Arrow ?? DownArrow }
179- className = { classes . rotation }
180- style = { {
181- transform : `rotate(${ isModalVisible ? "180deg" : "0deg" } )` ,
182- ...styles [ Elements . ArrowIcon ]
183- } }
184- />
182+ { renderAsImage ( arrowIcon ) ?
183+ < img
184+ src = { arrowIcon as string ?? DownArrow }
185+ className = { classes . rotation }
186+ style = { {
187+ transform : `rotate(${ isModalVisible ? "180deg" : "0deg" } )` ,
188+ ...styles [ Elements . ArrowIcon ]
189+ } }
190+ /> :
191+ arrowIcon }
185192 </ button >
186193 </ div >
187194 { ! isModalVisible && helperText && (
0 commit comments