fix(Popover): hover mode (#453)

This commit is contained in:
KeJun
2023-07-27 20:35:27 +08:00
committed by GitHub
parent 3af39cacf7
commit 10890e6704
3 changed files with 41 additions and 10 deletions

View File

@@ -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>

View File

@@ -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

View File

@@ -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"
@@ -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 () {
@@ -145,6 +143,7 @@ export default defineComponent({
return {
// eslint-disable-next-line vue/no-dupe-keys
ui,
popover,
trigger,
container,
onMouseOver,