Skip to content

Commit 6a88fd5

Browse files
fix: double onClose on mobile dialog outClick (#2690)
* fix: double onClose on mobile dialog outClick * Fix CS * Add fix to Vue useOutsideClick * Update changelog * Fix CS --------- Co-authored-by: Jordan Pittman <jordan@cryptica.me>
1 parent 8505d7a commit 6a88fd5

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

packages/@headlessui-react/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Don't call `<Dialog>`'s `onClose` twice on mobile devices ([#2690](https://github.com/tailwindlabs/headlessui/pull/2690))
1113

1214
## [1.7.17] - 2023-08-17
1315

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

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { MutableRefObject, useEffect, useRef } from 'react'
22
import { FocusableMode, isFocusableElement } from '../utils/focus-management'
33
import { useDocumentEvent } from './use-document-event'
44
import { useWindowEvent } from './use-window-event'
5+
import { isMobile } from '../utils/platform'
56

67
type Container = MutableRefObject<HTMLElement | null> | HTMLElement | null
78
type ContainerCollection = Container[] | Set<Container>
@@ -125,6 +126,10 @@ export function useOutsideClick(
125126
useDocumentEvent(
126127
'click',
127128
(event) => {
129+
if (isMobile()) {
130+
return
131+
}
132+
128133
if (!initialClickTarget.current) {
129134
return
130135
}

packages/@headlessui-vue/CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Don't call `<Dialog>`'s `onClose` twice on mobile devices ([#2690](https://github.com/tailwindlabs/headlessui/pull/2690))
1113

1214
## [1.7.16] - 2023-08-17
1315

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

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FocusableMode, isFocusableElement } from '../utils/focus-management'
33
import { dom } from '../utils/dom'
44
import { useDocumentEvent } from './use-document-event'
55
import { useWindowEvent } from './use-window-event'
6+
import { isMobile } from '../utils/platform'
67

78
type Container = Ref<HTMLElement | null> | HTMLElement | null
89
type ContainerCollection = Container[] | Set<Container>
@@ -108,6 +109,10 @@ export function useOutsideClick(
108109
useDocumentEvent(
109110
'click',
110111
(event) => {
112+
if (isMobile()) {
113+
return
114+
}
115+
111116
if (!initialClickTarget.value) {
112117
return
113118
}

0 commit comments

Comments
 (0)