Skip to content

Commit

Permalink
ensure relatedTarget is an HTMLElement
Browse files Browse the repository at this point in the history
Or in other words, Robin trust the type system...

I was assuming that this was always an `HTMLElement` or `null` but
that's not the case. Just using `e.relatedTarget` shows that `dataset`
is not always available.
  • Loading branch information
RobinMalfait committed Jan 24, 2023
1 parent 1d94d15 commit 6b00b96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export let FocusTrap = Object.assign(
let allContainers = new Set(containers?.current)
allContainers.add(container)

let relatedTarget = e.relatedTarget as HTMLElement | null
if (!relatedTarget) return
let relatedTarget = e.relatedTarget
if (!(relatedTarget instanceof HTMLElement)) return

// Known guards, leave them alone!
if (relatedTarget.dataset.headlessuiFocusGuard === 'true') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ export let FocusTrap = Object.assign(
let allContainers = new Set(props.containers?.value)
allContainers.add(container)

let relatedTarget = e.relatedTarget as HTMLElement | null
if (!relatedTarget) return
let relatedTarget = e.relatedTarget
if (!(relatedTarget instanceof HTMLElement)) return

// Known guards, leave them alone!
if (relatedTarget.dataset.headlessuiFocusGuard === 'true') {
Expand Down

0 comments on commit 6b00b96

Please sign in to comment.