Skip to content

Commit

Permalink
fix(Popover): hover mode (#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
KeJunMao committed Jul 27, 2023
1 parent 3af39ca commit 10890e6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
11 changes: 11 additions & 0 deletions docs/components/content/examples/PopoverExampleMode.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<UPopover mode="hover">
<UButton color="white" label="Open" trailing-icon="i-heroicons-chevron-down-20-solid" />

<template #panel>
<div class="p-4">
<Placeholder class="h-20 w-48" />
</div>
</template>
</UPopover>
</template>
21 changes: 21 additions & 0 deletions docs/content/6.overlays/3.popover.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@ links:
```
::

### Mode

Use the `mode` prop to switch between `click` and `hover` modes.

::component-example
#default
:popover-example-mode
#code
```vue
<template>
<UPopover mode="hover">
<UButton color="white" label="Open" trailing-icon="i-heroicons-chevron-down-20-solid" />
<template #panel>
<!-- Content -->
</template>
</UPopover>
</template>
```
::

## Props

:component-props
Expand Down
19 changes: 9 additions & 10 deletions src/runtime/components/overlays/Popover.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<HPopover v-slot="{ open, close }" :class="ui.wrapper" @mouseleave="onMouseLeave">
<HPopover ref="popover" v-slot="{ open, close }" :class="ui.wrapper" @mouseleave="onMouseLeave">
<HPopoverButton
ref="trigger"
as="div"
Expand Down Expand Up @@ -85,21 +85,19 @@ export default defineComponent({
const [trigger, container] = usePopper(popper.value)
// https://github.com/tailwindlabs/headlessui/blob/f66f4926c489fc15289d528294c23a3dc2aee7b1/packages/%40headlessui-vue/src/components/popover/popover.ts#L151
const popover = ref<any>(null)
const popoverApi = ref<any>(null)
let openTimeout: NodeJS.Timeout | null = null
let closeTimeout: NodeJS.Timeout | null = null
onMounted(() => {
setTimeout(() => {
// @ts-expect-error internals
const popoverProvides = trigger.value?.$.provides
if (!popoverProvides) {
return
}
const popoverProvidesSymbols = Object.getOwnPropertySymbols(popoverProvides)
popoverApi.value = popoverProvidesSymbols.length && popoverProvides[popoverProvidesSymbols[0]]
}, 200)
const popoverProvides = popover.value?.$.provides
if (!popoverProvides) {
return
}
const popoverProvidesSymbols = Object.getOwnPropertySymbols(popoverProvides)
popoverApi.value = popoverProvidesSymbols.length && popoverProvides[popoverProvidesSymbols[0]]
})
function onMouseOver () {
Expand Down Expand Up @@ -145,6 +143,7 @@ export default defineComponent({
return {
// eslint-disable-next-line vue/no-dupe-keys
ui,
popover,
trigger,
container,
onMouseOver,
Expand Down

1 comment on commit 10890e6

@vercel
Copy link

@vercel vercel bot commented on 10890e6 Jul 27, 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.nuxtlabs.com
ui-git-dev-nuxtlabs.vercel.app
ui-nuxtlabs.vercel.app

Please sign in to comment.