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

Fix logout dropdown hide on outside click #565

Merged
merged 3 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion client/src/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export default function Header({
const [searchText, setSearchText] = React.useState("");
const [showAccountDropdown, setShowAccountDropdown] = React.useState(false);

const profileDropdownEl = React.useRef(null);
React.useEffect(() => {
if (showAccountDropdown) {
profileDropdownEl.current.focus();
}
}, [showAccountDropdown]);

const handleSearch = (value) => {
value = value || searchText;

Expand Down Expand Up @@ -100,7 +107,12 @@ export default function Header({
<div className={`${iconStyles.chevronDownG} ${style.arrow}`}></div>
)}
{showAccountDropdown && (
<ul className={style.dropdown}>
<ul
tabIndex="0"
className={style.dropdown}
ref={profileDropdownEl}
onBlur={() => setShowAccountDropdown(false)}
>
<li
className={style.dropdownItem}
onClick={() => logoutWithRedirect()}
Expand Down
4 changes: 4 additions & 0 deletions client/src/components/Header/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
overflow: hidden;

&:focus {
outline: none;
}
}

.dropdownItem {
Expand Down