Skip to content

Commit c92feaa

Browse files
authored
Stop propagation on the Popover Button (#1263)
* stop propagation on Popover Button This is only done on buttons that are **not** inside the Popover Panel. * update changelog * trigger CI
1 parent 2dbc38c commit c92feaa

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- Add `multi` value support for Listbox & Combobox ([#1243](https://github.com/tailwindlabs/headlessui/pull/1243))
3030
- Improve Combobox Input value ([#1248](https://github.com/tailwindlabs/headlessui/pull/1248))
3131
- Fix Tree-shaking support ([#1247](https://github.com/tailwindlabs/headlessui/pull/1247))
32+
- Stop propagation on the Popover Button ([#1263](https://github.com/tailwindlabs/headlessui/pull/1263))
3233

3334
### Added
3435

@@ -60,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6061
- Add `multi` value support for Listbox & Combobox ([#1243](https://github.com/tailwindlabs/headlessui/pull/1243))
6162
- Improve Combobox Input value ([#1248](https://github.com/tailwindlabs/headlessui/pull/1248))
6263
- Fix Tree-shaking support ([#1247](https://github.com/tailwindlabs/headlessui/pull/1247))
64+
- Stop propagation on the Popover Button ([#1263](https://github.com/tailwindlabs/headlessui/pull/1263))
6365

6466
### Added
6567

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

+2
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ let Button = forwardRefWithAs(function Button<TTag extends ElementType = typeof
461461
dispatch({ type: ActionTypes.ClosePopover })
462462
state.button?.focus() // Re-focus the original opening Button
463463
} else {
464+
event.preventDefault()
465+
event.stopPropagation()
464466
if (state.popoverState === PopoverStates.Closed) closeOthers?.(state.buttonId)
465467
state.button?.focus()
466468
dispatch({ type: ActionTypes.TogglePopover })

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,14 @@ export let PopoverButton = defineComponent({
363363
}
364364
}
365365

366-
function handleClick() {
366+
function handleClick(event: MouseEvent) {
367367
if (props.disabled) return
368368
if (isWithinPanel) {
369369
api.closePopover()
370370
dom(api.button)?.focus() // Re-focus the original opening Button
371371
} else {
372+
event.preventDefault()
373+
event.stopPropagation()
372374
if (api.popoverState.value === PopoverStates.Closed) closeOthers?.(api.buttonId)
373375
dom(api.button)?.focus()
374376
api.togglePopover()

0 commit comments

Comments
 (0)