Skip to content
Snippets Groups Projects
Unverified Commit aa4c9533 authored by Timothy Carambat's avatar Timothy Carambat Committed by GitHub
Browse files

Feature/use escape key to close documents modal (#2222)


* Add ability to use Esc keypress to close modal for documents

* move escape close to hook

---------

Co-authored-by: default avatarMr Simon C <iamontheinternet@yahoo.com>
parent 7594841d
Branches
Tags
No related merge requests found
......@@ -127,19 +127,32 @@ const ModalTabSwitcher = ({ selectedTab, setSelectedTab }) => {
</div>
);
};
export function useManageWorkspaceModal() {
const { user } = useUser();
const [showing, setShowing] = useState(false);
const showModal = () => {
function showModal() {
if (user?.role !== "default") {
setShowing(true);
}
};
}
const hideModal = () => {
function hideModal() {
setShowing(false);
};
}
useEffect(() => {
function onEscape(event) {
if (!showing || event.key !== "Escape") return;
setShowing(false);
}
document.addEventListener("keydown", onEscape);
return () => {
document.removeEventListener("keydown", onEscape);
};
}, [showing]);
return { showing, showModal, hideModal };
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment