@@ -15,7 +15,10 @@ type PropsType = {
1515 clearConversationSearch : ( ) => void ;
1616 clearSearch : ( ) => void ;
1717 disabled ?: boolean ;
18+ endConversationSearch : ( ) => void ;
19+ endSearch : ( ) => void ;
1820 i18n : LocalizerType ;
21+ isSearchingGlobally : boolean ;
1922 onEnterKeyDown ?: (
2023 clearSearch : ( ) => void ,
2124 showConversation : ShowConversationType
@@ -31,7 +34,10 @@ export function LeftPaneSearchInput({
3134 clearConversationSearch,
3235 clearSearch,
3336 disabled,
37+ endConversationSearch,
38+ endSearch,
3439 i18n,
40+ isSearchingGlobally,
3541 onEnterKeyDown,
3642 searchConversation,
3743 searchTerm,
@@ -46,6 +52,7 @@ export function LeftPaneSearchInput({
4652 searchConversation ?. id
4753 ) ;
4854 const prevSearchCounter = usePrevious ( startSearchCounter , startSearchCounter ) ;
55+ const wasSearchingGlobally = usePrevious ( false , isSearchingGlobally ) ;
4956
5057 useEffect ( ( ) => {
5158 // When user chooses to search in a given conversation we focus the field for them
@@ -56,14 +63,19 @@ export function LeftPaneSearchInput({
5663 inputRef . current ?. focus ( ) ;
5764 }
5865 // When user chooses to start a new search, we focus the field
59- if ( startSearchCounter !== prevSearchCounter ) {
66+ if (
67+ ( isSearchingGlobally && ! wasSearchingGlobally ) ||
68+ startSearchCounter !== prevSearchCounter
69+ ) {
6070 inputRef . current ?. select ( ) ;
6171 }
6272 } , [
6373 prevSearchConversationId ,
6474 prevSearchCounter ,
6575 searchConversation ,
6676 startSearchCounter ,
77+ isSearchingGlobally ,
78+ wasSearchingGlobally ,
6779 ] ) ;
6880
6981 const changeValue = ( nextSearchTerm : string ) => {
@@ -82,11 +94,6 @@ export function LeftPaneSearchInput({
8294 }
8395 } ;
8496
85- const clearAndFocus = ( ) => {
86- clearSearch ( ) ;
87- inputRef . current ?. focus ( ) ;
88- } ;
89-
9097 const label = searchConversation ? i18n ( 'icu:searchIn' ) : i18n ( 'icu:search' ) ;
9198
9299 return (
@@ -98,7 +105,7 @@ export function LeftPaneSearchInput({
98105 moduleClassName = "LeftPaneSearchInput"
99106 onBlur = { ( ) => {
100107 if ( ! searchConversation && ! searchTerm ) {
101- clearSearch ( ) ;
108+ endSearch ( ) ;
102109 }
103110 } }
104111 onKeyDown = { event => {
@@ -112,10 +119,14 @@ export function LeftPaneSearchInput({
112119 changeValue ( event . currentTarget . value ) ;
113120 } }
114121 onClear = { ( ) => {
115- if ( searchConversation && searchTerm ) {
116- changeValue ( '' ) ;
122+ if ( searchTerm ) {
123+ clearSearch ( ) ;
124+ inputRef . current ?. focus ( ) ;
125+ } else if ( searchConversation ) {
126+ endConversationSearch ( ) ;
127+ inputRef . current ?. focus ( ) ;
117128 } else {
118- clearAndFocus ( ) ;
129+ inputRef . current ?. blur ( ) ;
119130 }
120131 } }
121132 ref = { inputRef }
@@ -151,7 +162,7 @@ export function LeftPaneSearchInput({
151162 < button
152163 aria-label = { i18n ( 'icu:clearSearch' ) }
153164 className = "LeftPaneSearchInput__in-conversation-pill__x-button"
154- onClick = { clearAndFocus }
165+ onClick = { endConversationSearch }
155166 type = "button"
156167 />
157168 </ div >
0 commit comments