Skip to content

Commit

Permalink
Merge pull request #1108 from artchen-db/main
Browse files Browse the repository at this point in the history
fix: focus trap did not work for shadow root
  • Loading branch information
JohannesKlauss authored Jan 4, 2024
2 parents 12e2021 + 0617c9f commit 0663c4b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/useHotkeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ export default function useHotkeys<T extends HTMLElement>(

// TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE
// REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WON'T TRIGGER THE HOTKEY.
if (
ref.current !== null &&
document.activeElement !== ref.current &&
!ref.current.contains(document.activeElement)
) {
stopPropagation(e)

return
if (ref.current !== null) {
const rootNode = ref.current.getRootNode()
if (
(rootNode instanceof Document || rootNode instanceof ShadowRoot) &&
rootNode.activeElement !== ref.current &&
!ref.current.contains(rootNode.activeElement)
) {
stopPropagation(e)
return
}
}

if ((e.target as HTMLElement)?.isContentEditable && !memoisedOptions?.enableOnContentEditable) {
Expand Down

1 comment on commit 0663c4b

@vercel
Copy link

@vercel vercel bot commented on 0663c4b Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.