Skip to content

Commit

Permalink
feat: close resume and calendar on escape
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronbrill committed May 23, 2022
1 parent 7d526dc commit 31a9cdd
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/components/KBar/KBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import { Resume, Mask } from "@Components/Resume/Resume";
import { Calendar } from "@Components/Calendar/Calendar";
import { H } from "highlight.run";
Expand All @@ -25,6 +25,18 @@ const KBar = ({ children }: KBarProps) => {
const [showCalendar, setShowCalendar] = useState(false);
const closeCalendar = () => setShowCalendar(false);

useEffect(() => {
function handleEscapeKey(event: KeyboardEvent) {
if (event.code === "Escape") {
closeModal();
closeCalendar();
}
}

document.addEventListener("keydown", handleEscapeKey);
return () => document.removeEventListener("keydown", handleEscapeKey);
}, []);

const notifier = new Notyf({
duration: 3500,
position: {
Expand Down

1 comment on commit 31a9cdd

@vercel
Copy link

@vercel vercel bot commented on 31a9cdd May 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.