Skip to content

Commit 3684860

Browse files
committed
fix: stop propagation of handled keyboard events
Prevent parent modals (e.g. Radix UI, MUI) from also acting on Escape or arrow keys that the lightbox has already handled — without this, pressing Escape inside a nested lightbox would close both the lightbox and the surrounding dialog.
1 parent ab1b563 commit 3684860

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/modules/Navigation/useKeyboardNavigation.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export function useKeyboardNavigation<T extends Element>(subscribeSensors: UseSe
3636
if (!(isRTL ? prevDisabled : nextDisabled)) (isRTL ? prev : next)();
3737
break;
3838
default:
39+
return;
3940
}
41+
// Prevent parent modals (e.g. Radix UI, MUI) from also acting on this keystroke —
42+
// without this, pressing Escape inside the lightbox would close both the lightbox
43+
// and the surrounding dialog.
44+
event.stopPropagation();
4045
});
4146

4247
React.useEffect(() => subscribeSensors(EVENT_ON_KEY_DOWN, handleKeyDown), [subscribeSensors, handleKeyDown]);

0 commit comments

Comments
 (0)