@@ -55,6 +55,7 @@ export class SearchBarInner extends Component {
55
55
this . getDropdownPopup = this . getDropdownPopup . bind ( this ) ;
56
56
this . getSuggestionList = this . getSuggestionList . bind ( this ) ;
57
57
this . handleSearchChange = this . handleSearchChange . bind ( this ) ;
58
+ this . handleClickOutside = this . handleClickOutside . bind ( this ) ;
58
59
// using debounce to avoid processing or requesting too much
59
60
this . updateSuggestionListWithNewSearch = _ . debounce (
60
61
this . updateSuggestionListWithNewSearch . bind ( this ) , 400 ,
@@ -66,6 +67,10 @@ export class SearchBarInner extends Component {
66
67
this . apiService = getService ( { spaceName : 'EDU' } ) ;
67
68
}
68
69
70
+ componentWillUnmount ( ) {
71
+ document . removeEventListener ( 'mousedown' , this . handleClickOutside ) ;
72
+ }
73
+
69
74
/**
70
75
* Set the search field ref
71
76
*/
@@ -164,13 +169,13 @@ export class SearchBarInner extends Component {
164
169
className = { theme [ 'group-cell' ] }
165
170
onClick = { ( ) => {
166
171
window . location . href = ( item . externalArticle && item . contentUrl )
167
- ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . title } ` ;
172
+ ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . slug || item . title } ` ;
168
173
} }
169
174
onKeyPress = { _ . noop }
170
175
>
171
176
< a
172
177
className = { theme . articleLink }
173
- href = { ( item . externalArticle && item . contentUrl ) ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . title } ` }
178
+ href = { ( item . externalArticle && item . contentUrl ) ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . slug || item . title } ` }
174
179
target = { ( item . externalArticle && item . contentUrl ) ? '_blank' : '_self' }
175
180
onClick = { ( e ) => {
176
181
e . nativeEvent . stopImmediatePropagation ( ) ;
@@ -215,13 +220,13 @@ export class SearchBarInner extends Component {
215
220
className = { theme [ 'group-cell' ] }
216
221
onClick = { ( ) => {
217
222
window . location . href = ( item . externalArticle && item . contentUrl )
218
- ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . title } ` ;
223
+ ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . slug || item . title } ` ;
219
224
} }
220
225
onKeyPress = { _ . noop }
221
226
>
222
227
< a
223
228
className = { theme . articleLink }
224
- href = { ( item . externalArticle && item . contentUrl ) ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . title } ` }
229
+ href = { ( item . externalArticle && item . contentUrl ) ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . slug || item . title } ` }
225
230
target = { ( item . externalArticle && item . contentUrl ) ? '_blank' : '_self' }
226
231
onClick = { ( e ) => {
227
232
e . nativeEvent . stopImmediatePropagation ( ) ;
@@ -267,7 +272,7 @@ export class SearchBarInner extends Component {
267
272
>
268
273
< a
269
274
className = { theme . forumLink }
270
- href = { ( item . externalArticle && item . contentUrl ) ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . title } ` }
275
+ href = { ( item . externalArticle && item . contentUrl ) ? item . contentUrl : `${ config . TC_EDU_BASE_PATH } ${ config . TC_EDU_ARTICLES_PATH } /${ item . slug || item . title } ` }
271
276
target = { ( item . externalArticle && item . contentUrl ) ? '_blank' : '_self' }
272
277
>
273
278
< span className = { theme [ 'cell-text' ] } >
@@ -317,6 +322,13 @@ export class SearchBarInner extends Component {
317
322
) ) ;
318
323
}
319
324
325
+ handleClickOutside ( e ) {
326
+ if ( this . popupSearchResultRef && ! this . popupSearchResultRef . contains ( e . target ) ) {
327
+ this . setState ( { isShowSuggestion : false } ) ;
328
+ document . removeEventListener ( 'mousedown' , this . handleClickOutside ) ;
329
+ }
330
+ }
331
+
320
332
/**
321
333
* Update size of popup search result
322
334
*/
@@ -453,14 +465,10 @@ export class SearchBarInner extends Component {
453
465
ref = { this . setSearchFieldRef }
454
466
type = "text"
455
467
placeholder = "Search..."
456
- onBlur = { ( ) => {
457
- _ . delay ( ( ) => {
458
- this . setState ( { isShowSuggestion : false } ) ;
459
- } , 100 ) ;
460
- } }
461
468
onFocus = { ( e ) => {
462
469
this . updateSuggestionListWithNewSearch ( e . target . value ) ;
463
470
this . setState ( { isShowSuggestion : true , isShowFilterPopup : false } ) ;
471
+ document . addEventListener ( 'mousedown' , this . handleClickOutside ) ;
464
472
} }
465
473
onChange = { this . handleSearchChange }
466
474
/>
0 commit comments