Skip to content

Commit

Permalink
fix: focus trap did not work for shadow root
Browse files Browse the repository at this point in the history
  • Loading branch information
artchen-db committed Dec 27, 2023
1 parent f5e0ddd commit 0617c9f
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 @@ -70,14 +70,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

0 comments on commit 0617c9f

Please sign in to comment.