This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -50,13 +50,16 @@ export default function SearchGlobal({ keyword }) {
50
50
const [ windowWidth , setWindowWidth ] = React . useState ( window . innerWidth ) ;
51
51
const [ orderBy , setOrderBy ] = React . useState ( config . DEFAULT_SORT_ORDER ) ;
52
52
const [ totalPages , setTotalPages ] = React . useState ( 0 ) ;
53
+ const dropdownRef = React . useRef ( null ) ;
53
54
54
55
const usersPerPage = config . ITEMS_PER_PAGE ;
55
56
56
57
React . useEffect ( ( ) => {
57
58
window . addEventListener ( "resize" , updateWindowDimensions ) ;
59
+ window . addEventListener ( "click" , onWholeContentClick ) ;
58
60
return ( ) => {
59
61
window . removeEventListener ( "resize" , updateWindowDimensions ) ;
62
+ window . removeEventListener ( "click" , onWholeContentClick ) ;
60
63
} ;
61
64
} ) ;
62
65
@@ -241,6 +244,12 @@ export default function SearchGlobal({ keyword }) {
241
244
const updateWindowDimensions = ( ) => {
242
245
setWindowWidth ( window . innerWidth ) ;
243
246
} ;
247
+
248
+ const onWholeContentClick = ( evt ) => {
249
+ if ( dropdownRef . current && ! dropdownRef . current . contains ( evt . target ) ) {
250
+ setSortByDropdownShown ( false ) ;
251
+ }
252
+ }
244
253
245
254
return (
246
255
< >
@@ -259,6 +268,7 @@ export default function SearchGlobal({ keyword }) {
259
268
</ div >
260
269
< div
261
270
className = { style . sort }
271
+ ref = { dropdownRef }
262
272
onClick = { ( ) => setSortByDropdownShown ( ! sortByDropdownShown ) }
263
273
style = { {
264
274
marginRight :
You can’t perform that action at this time.
0 commit comments