Skip to content

Commit

Permalink
feat(challenge modal): close with escape key
Browse files Browse the repository at this point in the history
  • Loading branch information
plebeius-eth committed Jan 24, 2025
1 parent f952044 commit 66a766b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/challenge-modal/challenge-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { FloatingFocusManager, useClick, useDismiss, useFloating, useId, useInteractions, useRole } from '@floating-ui/react';
import { Challenge as ChallengeType, useComment } from '@plebbit/plebbit-react-hooks';
import { useTranslation } from 'react-i18next';
Expand Down Expand Up @@ -54,6 +54,16 @@ const Challenge = ({ challenge, closeModal }: ChallengeProps) => {
}
};

useEffect(() => {
const onEscapeKey = (e: KeyboardEvent) => {
if (e.key === 'Escape') {
closeModal();
}
};
document.addEventListener('keydown', onEscapeKey);
return () => document.removeEventListener('keydown', onEscapeKey);
}, [closeModal]);

return (
<div className={styles.container}>
<div className={styles.title}>{t('challenge_from', { subplebbit: shortSubplebbitAddress || subplebbitAddress })}</div>
Expand Down

0 comments on commit 66a766b

Please sign in to comment.