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

Commit 8efad3b

Browse files
author
sanju singh
committed
Fix logout dropdown hide on outside click
1 parent 974f0ca commit 8efad3b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

client/src/components/Header/index.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ export default function Header({
2929
const [searchText, setSearchText] = React.useState("");
3030
const [showAccountDropdown, setShowAccountDropdown] = React.useState(false);
3131

32+
const profileDropdownEl = React.useRef(null);
33+
React.useEffect(() => {
34+
if (showAccountDropdown) {
35+
profileDropdownEl.current.focus();
36+
}
37+
}, [showAccountDropdown]);
38+
3239
const handleSearch = (value) => {
3340
value = value || searchText;
3441

@@ -101,7 +108,12 @@ export default function Header({
101108
<div className={`${iconStyles.chevronDownG} ${style.arrow}`}></div>
102109
)}
103110
{showAccountDropdown && (
104-
<ul className={style.dropdown}>
111+
<ul
112+
tabIndex="0"
113+
className={style.dropdown}
114+
ref={profileDropdownEl}
115+
onBlur={() => setShowAccountDropdown(false)}
116+
>
105117
<li
106118
className={style.dropdownItem}
107119
onClick={() => logoutWithRedirect()}

0 commit comments

Comments
 (0)