mirror of
https://github.com/lukevella/rallly.git
synced 2025-04-30 10:46:35 +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 ParticipantRowForm from "./desktop-poll/participant-row-form";
|
||||||
import PollHeader from "./desktop-poll/poll-header";
|
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>(
|
const useIsOverflowing = <E extends Element | null>(
|
||||||
ref: React.RefObject<E>,
|
ref: React.RefObject<E>,
|
||||||
) => {
|
) => {
|
||||||
|
@ -204,6 +222,7 @@ const DesktopPoll: React.FunctionComponent = () => {
|
||||||
</TooltipContent>
|
</TooltipContent>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
{expanded ? <EscapeListener onEscape={collapse} /> : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue