Skip to content

Commit

Permalink
feat: cancel editing on ESC key press (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
KidesLeo authored Oct 22, 2022
1 parent 3f8eb78 commit 2722490
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/src/components/Chat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,23 @@ const Chat = () => {
.timeout(10000)
.emit('typing', { chatId: currentChatId, isTyping: false });
};

// Clear chat when escape is pressed
useEffect(() => {
const keyDownHandler = event => {

if (event.key === 'Escape' && editing.isediting) {
event.preventDefault();
cancelEdit();
};
}

document.addEventListener('keydown', keyDownHandler);

return () => {
document.removeEventListener('keydown', keyDownHandler);
};
}, [editing]);

const handleTypingStatus = debounce((e) => {
if (e.target.value.length > 0) {
Expand Down

1 comment on commit 2722490

@vercel
Copy link

@vercel vercel bot commented on 2722490 Oct 22, 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.