@@ -16,6 +16,7 @@ import {
1616import { SpanWithLinkStyle } from '../Style/linkStyles' ;
1717import { MatchingPerson , SearchBarWrapper } from '../Style/sharedStyles' ;
1818import AddPersonForm from './AddPersonForm' ;
19+ import CrossIcon from '../../../img/global/svg-icons/cross.svg' ;
1920
2021const LIMIT_NUMBER_SHOWN = 20 ;
2122
@@ -38,7 +39,7 @@ const AddPersonDrawerMainContent = () => {
3839 const [ teamMemberPersonIdList ] = useState ( [ ] ) ;
3940 const [ matchingCountText , setMatchingCountText ] = useState ( '' ) ;
4041
41- const searchStringInputRef = useRef ( '' ) ;
42+ const searchStringInputRef = useRef ( null ) ;
4243
4344 const updateRemainingPeopleToAdd = ( ) => {
4445 // console.log('initializeTheRemainingPeopleToAddListList in AddPersonDrawerMainContent');
@@ -103,7 +104,7 @@ const AddPersonDrawerMainContent = () => {
103104 setSearchResultsList ( undefined ) ;
104105 } else {
105106 const isMatch = ( element ) => ( element . lastName . toLowerCase ( ) . includes ( currentValue . toLowerCase ( ) ) ||
106- element . firstName . toLowerCase ( ) . includes ( currentValue . toLowerCase ( ) ) ) ;
107+ element . firstName . toLowerCase ( ) . includes ( currentValue . toLowerCase ( ) ) || element . firstNamePreferred ?. toLowerCase ( ) . includes ( currentValue . toLowerCase ( ) ) ) ;
107108 const matchingElements = remainingPeopleToAdd ? remainingPeopleToAdd . filter ( ( element ) => isMatch ( element ) ) : { } ;
108109 if ( matchingElements && matchingElements . length ) {
109110 setSearchResultsList ( matchingElements ) ;
@@ -115,6 +116,12 @@ const AddPersonDrawerMainContent = () => {
115116 }
116117 } ;
117118
119+ const clearSearch = ( ) => {
120+ searchStringInputRef . current . value = '' ;
121+ setSearchResultsList ( undefined ) ;
122+ setMatchingCountText ( '' ) ;
123+ } ;
124+
118125 const addClicked = ( incomingPerson ) => {
119126 const personId = incomingPerson ? incomingPerson . personId : - 1 ;
120127 const teamId = team ? team . teamId : - 1 ;
@@ -153,6 +160,16 @@ const AddPersonDrawerMainContent = () => {
153160 placeholder = "Search by name"
154161 defaultValue = ""
155162 sx = { { minWidth : '250px' } }
163+ InputProps = { {
164+ endAdornment : searchStringInputRef . current ?. value ? (
165+ < span
166+ onClick = { clearSearch }
167+ style = { { cursor : 'pointer' , display : 'flex' , alignItems : 'center' } }
168+ >
169+ < img src = { CrossIcon } alt = "Clear search" style = { { width : 14 , height : 14 } } />
170+ </ span >
171+ ) : null ,
172+ } }
156173 />
157174 < MatchingPerson > { matchingCountText } </ MatchingPerson >
158175 </ SearchBarWrapper >
0 commit comments