mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-29 10:16:32 +02:00
✨ Close expanded poll with esc key (#1253)
This commit is contained in:
parent
c57428df83
commit
acb7aa88da
1 changed files with 19 additions and 0 deletions
|
@ -37,6 +37,24 @@ import ParticipantRow from "./desktop-poll/participant-row";
|
|||
import ParticipantRowForm from "./desktop-poll/participant-row-form";
|
||||
import PollHeader from "./desktop-poll/poll-header";
|
||||
|
||||
function EscapeListener({ onEscape }: { onEscape: () => void }) {
|
||||
React.useEffect(() => {
|
||||
const handleEscape = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
onEscape();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener("keydown", handleEscape);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleEscape);
|
||||
};
|
||||
}, [onEscape]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
const useIsOverflowing = <E extends Element | null>(
|
||||
ref: React.RefObject<E>,
|
||||
) => {
|
||||
|
@ -204,6 +222,7 @@ const DesktopPoll: React.FunctionComponent = () => {
|
|||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
{expanded ? <EscapeListener onEscape={collapse} /> : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue