Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ff77619

Browse files
authoredJul 24, 2020
Update Global.jsx
1 parent dc155a9 commit ff77619

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed
 

‎client/src/pages/Search/Global.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ export default function SearchGlobal({ keyword }) {
5050
const [windowWidth, setWindowWidth] = React.useState(window.innerWidth);
5151
const [orderBy, setOrderBy] = React.useState(config.DEFAULT_SORT_ORDER);
5252
const [totalPages, setTotalPages] = React.useState(0);
53+
const dropdownRef = React.useRef(null);
5354

5455
const usersPerPage = config.ITEMS_PER_PAGE;
5556

5657
React.useEffect(() => {
5758
window.addEventListener("resize", updateWindowDimensions);
59+
window.addEventListener("click", onWholeContentClick);
5860
return () => {
5961
window.removeEventListener("resize", updateWindowDimensions);
62+
window.removeEventListener("click", onWholeContentClick);
6063
};
6164
});
6265

@@ -241,6 +244,12 @@ export default function SearchGlobal({ keyword }) {
241244
const updateWindowDimensions = () => {
242245
setWindowWidth(window.innerWidth);
243246
};
247+
248+
const onWholeContentClick = (evt) => {
249+
if(dropdownRef.current && !dropdownRef.current.contains(evt.target)) {
250+
setSortByDropdownShown(false);
251+
}
252+
}
244253

245254
return (
246255
<>
@@ -259,6 +268,7 @@ export default function SearchGlobal({ keyword }) {
259268
</div>
260269
<div
261270
className={style.sort}
271+
ref={dropdownRef}
262272
onClick={() => setSortByDropdownShown(!sortByDropdownShown)}
263273
style={{
264274
marginRight:

0 commit comments

Comments
 (0)
This repository has been archived.