Skip to content

Commit 0e147a0

Browse files
Fix useOutsideClick, add improvements for ShadowDOM (#1914)
* Fix `useOutsideClick` not closing when clicking in ShadowDOM #1876 (comment) * use `getRootNode` in `useOutsideClick` for Vue * update changelog * run prettier Co-authored-by: Theodore Messinezis <[email protected]>
1 parent 1127a55 commit 0e147a0

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Fix `<Popover.Button as={Fragment} />` crash ([#1889](https://github.com/tailwindlabs/headlessui/pull/1889))
1313
- Expose `close` function for `Menu` and `Menu.Item` components ([#1897](https://github.com/tailwindlabs/headlessui/pull/1897))
14+
- Fix `useOutsideClick`, add improvements for ShadowDOM ([#1914](https://github.com/tailwindlabs/headlessui/pull/1914))
1415

1516
### Added
1617

packages/@headlessui-react/src/hooks/use-outside-click.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function useOutsideClick(
6060
}
6161

6262
// Ignore if the target doesn't exist in the DOM anymore
63-
if (!target.ownerDocument.documentElement.contains(target)) return
63+
if (!target.getRootNode().contains(target)) return
6464

6565
// Ignore if the target exists in one of the containers
6666
for (let container of _containers) {

packages/@headlessui-vue/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Expose `close` function for `Menu` and `MenuItem` components ([#1897](https://github.com/tailwindlabs/headlessui/pull/1897))
13+
- Fix `useOutsideClick`, add improvements for ShadowDOM ([#1914](https://github.com/tailwindlabs/headlessui/pull/1914))
1314

1415
## [1.7.3] - 2022-09-30
1516

packages/@headlessui-vue/src/hooks/use-outside-click.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function useOutsideClick(
3030
}
3131

3232
// Ignore if the target doesn't exist in the DOM anymore
33-
if (!target.ownerDocument.documentElement.contains(target)) return
33+
if (!target.getRootNode().contains(target)) return
3434

3535
let _containers = (function resolve(containers): ContainerCollection {
3636
if (typeof containers === 'function') {

0 commit comments

Comments
 (0)