Fire event on Popover close #1217
Replies: 5 comments
-
For vue part it can be solved with little changes (like currently implemented in Dialog) packages/@headlessui-vue/src/components/popover/popover.ts export let Popover = defineComponent({
...
emits: { close: (_close: boolean) => true },
...
setup(props, { emit, attrs, slots }) {
...
let api = {
...
close(focusableElement: HTMLElement | Ref<HTMLElement | null>) {
...
emit('close', false)
}
...
}
...
}
}) |
Beta Was this translation helpful? Give feedback.
-
Hi for react you can use that:
|
Beta Was this translation helpful? Give feedback.
-
For what it's worth if anyone else is struggling with the same thing, I was able to use a |
Beta Was this translation helpful? Give feedback.
-
Since this is not supported yet, a workaround in vue is to put the content of the PopoverPanel into its own component and fire the close event from the beforeUnmount lifecycle hook. |
Beta Was this translation helpful? Give feedback.
-
You can use a ref to watch if the PopoverPanel gets closed: Script tag: const popoverRef = ref(null)
watch(
() => popoverRef.value?.el,
(el) => {
if (!el) {
// someHandler()
}
},
) Template tag: <Popover>
<PopoverPanel ref="popoverRef" />
<Popover> |
Beta Was this translation helpful? Give feedback.
-
In some cases it is useful to know, if popover was closed or not. For example, to reset logic inside PopoverPanel (tabs navigation, etc.). Like
close
event in Dialog.Beta Was this translation helpful? Give feedback.
All reactions