Skip to content

Commit

Permalink
Feedback Widget: close on esc
Browse files Browse the repository at this point in the history
  • Loading branch information
nirnejak committed May 15, 2024
1 parent a940f59 commit cbaec8a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions components/FeedbackWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ const FeedbackWidget: React.FC = () => {
setIsWidgetOpen(false)
})

React.useEffect(() => {
const handleKeyDown = (e) => {
if (e.key === "Escape") {
setIsWidgetOpen(false)
}
}

if (isWidgetOpen) {
window.addEventListener("keyup", handleKeyDown)
}
return () => {
window.removeEventListener("keyup", handleKeyDown)
}
}, [isWidgetOpen])

const [formState, setFormState] = React.useState(defaultFormState)
const [isSending, setIsSending] = React.useState(false)
const [isSent, setIsSent] = React.useState(false)
Expand Down

0 comments on commit cbaec8a

Please sign in to comment.