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-select/docs/en-US.md b/packages/varlet-ui/src/menu-select/docs/en-US.md index 0a49c750af9..517205b4c96 100644 --- a/packages/varlet-ui/src/menu-select/docs/en-US.md +++ b/packages/varlet-ui/src/menu-select/docs/en-US.md @@ -300,7 +300,7 @@ const options = ref([ | `teleport` | The location of the menu mount | _TeleportProps['to'] \| false_ | `body` | | `disabled` | Whether to disable the menu | _boolean_ | `false` | | `trigger` | Menu trigger method, optional value is `click` `hover` `manual` | _string_ | `click` | -| `reference` | The associated trigger element selector is used to specify specific child elements as trigger elements | _string_ | `-` | +| `reference` | The trigger element associated with the menu, the `string` type is the descendant element selector of the menu component, the `HTMLElement` type is any specified element node | _string \| HTMLElement_ | `-` | | `elevation` | Elevation level, options `true` `false` and level of `0-24` | _string \| number \| boolean_| `true` | | `same-width` | Whether to same width as trigger element | _boolean_ | `false` | | `popover-class` | Class of the popover | _string_ | `-` | @@ -361,6 +361,7 @@ const options = ref([ | `open` | Open Menu | `-` | `-` | | `close` | Close Menu | `-` | `-` | | `resize` | This method can be called to redraw when the default slot element of Menu select changes its position and size | `-` | `-` | +| `setReference` ***3.7.2*** | Set the trigger element associated with the menu | `reference: consistent with the reference of the component attribute` | `-` | ### Events diff --git a/packages/varlet-ui/src/menu-select/docs/zh-CN.md b/packages/varlet-ui/src/menu-select/docs/zh-CN.md index 4a37d077ba3..d1530b51381 100644 --- a/packages/varlet-ui/src/menu-select/docs/zh-CN.md +++ b/packages/varlet-ui/src/menu-select/docs/zh-CN.md @@ -300,7 +300,7 @@ const options = ref([ | `teleport` | 菜单挂载的位置 | _TeleportProps['to'] \| false_ | `body` | | `disabled` | 是否禁用菜单 | _boolean_ | `false` | | `trigger` | 菜单触发方式,可选值为 `click` `hover` `manual` | _string_ | `click` | -| `reference` | 菜单关联的触发元素选择器,用于指定菜单的特定子元素为触发元素 | _string_ | `-` | +| `reference` | 菜单关联的触发元素,`string` 类型为菜单组件的子孙元素选择器, `HTMLElement` 类型为任意指定的元素节点 | _string \| HTMLElement_ | `-` | | `elevation` | 海拔高度,可选值为 `true` `false` 和 `0-24` 的等级 | _string \| number \| boolean_| `true` | | `same-width` | 是否与触发元素同宽 | _boolean_ | `false` | | `popover-class` | 弹出层的 class | _string_ | `-` | @@ -361,6 +361,7 @@ const options = ref([ | `open` | 打开 MenuSelect | `-` | `-` | | `close` | 关闭 MenuSelect | `-` | `-` | | `resize` | MenuSelect 默认插槽元素产生位置大小变化时可以调用此方法进行重绘 | `-` | `-` | +| `setReference` ***3.7.2*** | 设置 MenuSelect 关联的触发元素 | `reference: 与组件属性的 reference 一致` | `-` | ### 事件 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 @@