Skip to content

Commit 33c5c6e

Browse files
authored
Merge pull request #798 from tailwindlabs/stop-propagation-on-escape
Ensure we stop the event from propagating
2 parents 452b2c2 + 7f55847 commit 33c5c6e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

CHANGELOG.md

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

88
## [Unreleased - React]
99

10-
- Nothing yet!
10+
### Fixes
11+
12+
- Stop the event from propagating in the `Popover` component ([#798](https://github.com/tailwindlabs/headlessui/pull/798))
1113

1214
## [Unreleased - Vue]
1315

14-
- Nothing yet!
16+
### Fixes
17+
18+
- Stop the event from propagating in the `Popover` component ([#798](https://github.com/tailwindlabs/headlessui/pull/798))
1519

1620
## [@headlessui/react@v1.4.1] - 2021-08-30
1721

packages/@headlessui-react/src/components/popover/popover.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ let Button = forwardRefWithAs(function Button<TTag extends ElementType = typeof
353353
if (state.popoverState !== PopoverStates.Open) return closeOthers?.(state.buttonId)
354354
if (!internalButtonRef.current) return
355355
if (!internalButtonRef.current.contains(document.activeElement)) return
356+
event.preventDefault()
357+
event.stopPropagation()
356358
dispatch({ type: ActionTypes.ClosePopover })
357359
break
358360

@@ -603,6 +605,7 @@ let Panel = forwardRefWithAs(function Panel<TTag extends ElementType = typeof DE
603605
if (!internalPanelRef.current) return
604606
if (!internalPanelRef.current.contains(document.activeElement)) return
605607
event.preventDefault()
608+
event.stopPropagation()
606609
dispatch({ type: ActionTypes.ClosePopover })
607610
state.button?.focus()
608611
break

packages/@headlessui-vue/src/components/popover/popover.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ export let PopoverButton = defineComponent({
304304
if (api.popoverState.value !== PopoverStates.Open) return closeOthers?.(api.buttonId)
305305
if (!dom(api.button)) return
306306
if (!dom(api.button)?.contains(document.activeElement)) return
307+
event.preventDefault()
308+
event.stopPropagation()
307309
api.closePopover()
308310
break
309311

@@ -571,6 +573,7 @@ export let PopoverPanel = defineComponent({
571573
if (!dom(api.panel)) return
572574
if (!dom(api.panel)?.contains(document.activeElement)) return
573575
event.preventDefault()
576+
event.stopPropagation()
574577
api.closePopover()
575578
dom(api.button)?.focus()
576579
break

0 commit comments

Comments
 (0)