Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 120fad5

Browse files
Merge pull request #560 from topcoder-platform/issue_102
issue 102 fix
2 parents 512e6a9 + ff77619 commit 120fad5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

client/src/pages/Search/Global.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,18 @@ export default function SearchGlobal({ keyword }) {
5858
const [windowWidth, setWindowWidth] = React.useState(window.innerWidth);
5959
const [orderBy, setOrderBy] = React.useState(config.DEFAULT_SORT_ORDER);
6060
const [totalPages, setTotalPages] = React.useState(0);
61+
const dropdownRef = React.useRef(null);
6162

6263
const prevOrderBy = usePrevious(orderBy);
6364

6465
const usersPerPage = config.ITEMS_PER_PAGE;
6566

6667
React.useEffect(() => {
6768
window.addEventListener("resize", updateWindowDimensions);
69+
window.addEventListener("click", onWholeContentClick);
6870
return () => {
6971
window.removeEventListener("resize", updateWindowDimensions);
72+
window.removeEventListener("click", onWholeContentClick);
7073
};
7174
});
7275

@@ -237,6 +240,7 @@ export default function SearchGlobal({ keyword }) {
237240
});
238241

239242
setUsers(data);
243+
setSortByDropdownShown(false);
240244
setTotalResults(Number(headers["x-total"]));
241245
setTotalPages(Number(headers["x-total-pages"]));
242246
}
@@ -255,6 +259,12 @@ export default function SearchGlobal({ keyword }) {
255259
const updateWindowDimensions = () => {
256260
setWindowWidth(window.innerWidth);
257261
};
262+
263+
const onWholeContentClick = (evt) => {
264+
if(dropdownRef.current && !dropdownRef.current.contains(evt.target)) {
265+
setSortByDropdownShown(false);
266+
}
267+
}
258268

259269
return (
260270
<>
@@ -273,6 +283,7 @@ export default function SearchGlobal({ keyword }) {
273283
</div>
274284
<div
275285
className={style.sort}
286+
ref={dropdownRef}
276287
onClick={() => setSortByDropdownShown(!sortByDropdownShown)}
277288
style={{
278289
marginRight:

0 commit comments

Comments
 (0)