Skip to content

Commit

Permalink
feat(Popover): open and close events (#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
connerblanton committed Dec 11, 2023
1 parent 4b04486 commit f32f578
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/runtime/components/overlays/Popover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</template>

<script lang="ts">
import { computed, ref, toRef, onMounted, defineComponent } from 'vue'
import { computed, ref, toRef, onMounted, defineComponent, watch } from 'vue'
import type { PropType } from 'vue'
import { defu } from 'defu'
import { Popover as HPopover, PopoverButton as HPopoverButton, PopoverPanel as HPopoverPanel } from '@headlessui/vue'
Expand Down Expand Up @@ -94,8 +94,8 @@ export default defineComponent({
default: () => ({})
}
},
emits: ['update:open'],
setup (props) {
emits: ['update:open', 'open', 'close'],
setup (props, { emit }) {
const { ui, attrs } = useUI('popover', toRef(props, 'ui'), config, toRef(props, 'class'))
const popper = computed<PopperOptions>(() => defu(props.mode === 'hover' ? { offsetDistance: 0 } : {}, props.popper, ui.value.popper as PopperOptions))
Expand Down Expand Up @@ -170,6 +170,11 @@ export default defineComponent({
}, props.closeDelay)
}
watch(() => popoverApi.value?.popoverState, (newValue: number, oldValue: number) => {
if (oldValue === undefined) return
emit(newValue === 0 ? 'open' : 'close')
})
return {
// eslint-disable-next-line vue/no-dupe-keys
ui,
Expand Down

1 comment on commit f32f578

@vercel
Copy link

@vercel vercel bot commented on f32f578 Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxt-js.vercel.app
ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com

Please sign in to comment.