Skip to content

Commit e7cfb05

Browse files
RobinMalfaitRaphael Melloni
andauthored
Fix useOutsideClick swallowing events inside ShadowDOM (#1886)
* check inside shadow dom for use-outside-click * update changelog Co-authored-by: Raphael Melloni <[email protected]>
1 parent 6cddc0f commit e7cfb05

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
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Improve `Portal` detection for `Popover` components ([#1842](https://github.com/tailwindlabs/headlessui/pull/1842))
13+
- Fix `useOutsideClick` swallowing events inside ShadowDOM ([#1876](https://github.com/tailwindlabs/headlessui/pull/1876))
1314

1415
## [1.7.2] - 2022-09-15
1516

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function useOutsideClick(
9696
'mousedown',
9797
(event) => {
9898
if (enabledRef.current) {
99-
initialClickTarget.current = event.target
99+
initialClickTarget.current = event.composedPath?.()?.[0] || event.target
100100
}
101101
},
102102
true

packages/@headlessui-vue/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Call `displayValue` with a v-model of `ref(undefined)` on `ComboboxInput` ([#1865](https://github.com/tailwindlabs/headlessui/pull/1865))
1313
- Improve `Portal` detection for `Popover` components ([#1842](https://github.com/tailwindlabs/headlessui/pull/1842))
1414
- Fix crash when `children` are `undefined` ([#1885](https://github.com/tailwindlabs/headlessui/pull/1885))
15+
- Fix `useOutsideClick` swallowing events inside ShadowDOM ([#1876](https://github.com/tailwindlabs/headlessui/pull/1876))
1516

1617
## [1.7.2] - 2022-09-15
1718

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function useOutsideClick(
8282
'mousedown',
8383
(event) => {
8484
if (enabled.value) {
85-
initialClickTarget.value = event.target
85+
initialClickTarget.value = event.composedPath?.()?.[0] || event.target
8686
}
8787
},
8888
true

0 commit comments

Comments
 (0)