Skip to content

Commit

Permalink
Fix crash when reading headlessuiFocusGuard of relatedTarget in t…
Browse files Browse the repository at this point in the history
…he `FocusTrap` component (#2203)

* ensure `relatedTarget` is an `HTMLElement`

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.

* update changelog
  • Loading branch information
RobinMalfait authored Jan 24, 2023
1 parent 1d94d15 commit 6f205f0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix `failed to removeChild on Node` bug ([#2164](https://github.com/tailwindlabs/headlessui/pull/2164))
- Don’t overwrite classes during SSR when rendering fragments ([#2173](https://github.com/tailwindlabs/headlessui/pull/2173))
- Improve `Combobox` accessibility ([#2153](https://github.com/tailwindlabs/headlessui/pull/2153))
- Fix crash when reading `headlessuiFocusGuard` of `relatedTarget` in the `FocusTrap` component ([#2203](https://github.com/tailwindlabs/headlessui/pull/2203))

## [1.7.7] - 2022-12-16

Expand Down
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
1 change: 1 addition & 0 deletions packages/@headlessui-vue/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix `Tab` key with non focusable elements in `Popover.Panel` ([#2147](https://github.com/tailwindlabs/headlessui/pull/2147))
- Don’t overwrite classes during SSR when rendering fragments ([#2173](https://github.com/tailwindlabs/headlessui/pull/2173))
- Improve `Combobox` accessibility ([#2153](https://github.com/tailwindlabs/headlessui/pull/2153))
- Fix crash when reading `headlessuiFocusGuard` of `relatedTarget` in the `FocusTrap` component ([#2203](https://github.com/tailwindlabs/headlessui/pull/2203))

## [1.7.7] - 2022-12-16

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 6f205f0

Please sign in to comment.