Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/hooks/useGlobalKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect } from "react";
import { sendGTMEvent } from "@next/third-parties/google";
import { useEffect } from "react";

type KeyboardKey = KeyboardEvent["key"];

Expand Down Expand Up @@ -28,7 +28,7 @@ export function useGlobalKeyCallback() {
if (!(lowerKey in allHandlersStacks)) return;
if (shouldHandleAsNativeEvent(event)) return;
const handlersStack = allHandlersStacks[lowerKey];
for (let handler of handlersStack.reverse()) {
for (let handler of [...handlersStack].reverse()) {
if (handler()) {
event.preventDefault();
event.stopPropagation();
Expand Down Expand Up @@ -63,7 +63,9 @@ export const useCallbackOnKey = ({
return () => {
if (!isDisabled) {
const index = allHandlersStacks[lowerKey].indexOf(handler);
allHandlersStacks[lowerKey].splice(index, 1);
if (index > -1) {
allHandlersStacks[lowerKey].splice(index, 1);
}
}
};
}, [key, handler, isDisabled]);
Expand Down