From 5ca38fb55f7601f4c66742ea284ce207d876c633 Mon Sep 17 00:00:00 2001 From: haoziqaq <357229046@qq.com> Date: Wed, 4 Dec 2024 00:43:22 +0800 Subject: [PATCH] feat: enhance popover reference --- .../varlet-ui/src/menu-select/MenuSelect.vue | 9 +- packages/varlet-ui/src/menu/Menu.vue | 23 ++-- packages/varlet-ui/src/menu/props.ts | 4 +- packages/varlet-ui/src/menu/usePopover.ts | 109 ++++++++++++------ packages/varlet-ui/src/tooltip/Tooltip.vue | 23 ++-- packages/varlet-use/src/useEventListener.ts | 1 + 6 files changed, 96 insertions(+), 73 deletions(-) diff --git a/packages/varlet-ui/src/menu-select/MenuSelect.vue b/packages/varlet-ui/src/menu-select/MenuSelect.vue index 40e4ede4b6c..76ca18af85c 100644 --- a/packages/varlet-ui/src/menu-select/MenuSelect.vue +++ b/packages/varlet-ui/src/menu-select/MenuSelect.vue @@ -56,10 +56,11 @@ import { props } from './props' import { createNamespace, formatElevation } from '../utils/components' import { useMenuOptions, type MenuSelectProvider } from './provide' import { useSelectController } from '../select/useSelectController' -import { type MenuOptionProvider } from '../menu-option/provide' import { call, preventDefault } from '@varlet/shared' import { useEventListener, useVModel } from '@varlet/use' import { focusChildElementByKey } from '../utils/elements' +import { type MenuOptionProvider } from '../menu-option/provide' +import { type Reference } from '../menu/usePopover' const { name, n, classes } = createNamespace('menu-select') @@ -139,6 +140,11 @@ export default defineComponent({ menu.value?.resize() } + // expose + function setReference(reference: Reference) { + menu.value?.setReference(reference) + } + return { show, menu, @@ -149,6 +155,7 @@ export default defineComponent({ open, close, resize, + setReference, } }, }) diff --git a/packages/varlet-ui/src/menu/Menu.vue b/packages/varlet-ui/src/menu/Menu.vue index c0b588aafed..5bbff9daf04 100644 --- a/packages/varlet-ui/src/menu/Menu.vue +++ b/packages/varlet-ui/src/menu/Menu.vue @@ -1,11 +1,5 @@