@@ -3,6 +3,7 @@ import type { Ref } from 'vue'
3
3
import type {
4
4
Middleware ,
5
5
Placement ,
6
+ ReferenceElement ,
6
7
} from ' @floating-ui/vue'
7
8
import type { PrimitiveProps } from ' @/Primitive'
8
9
import { createContext , useForwardExpose , useSize } from ' @/shared'
@@ -59,7 +60,7 @@ export interface PopperContentProps extends PrimitiveProps {
59
60
alignOffset? : number
60
61
61
62
/**
62
- * When `true`, overrides the side andalign preferences
63
+ * When `true`, overrides the side and align preferences
63
64
* to prevent collisions with boundary edges.
64
65
*
65
66
* @defaultValue true
@@ -125,6 +126,14 @@ export interface PopperContentProps extends PrimitiveProps {
125
126
* @defaultValue false
126
127
*/
127
128
prioritizePosition? : boolean
129
+
130
+ /**
131
+ * The custom element or virtual element that will be set as the reference
132
+ * to position the floating element.
133
+ *
134
+ * If provided, it will replace the default anchor element.
135
+ */
136
+ reference? : ReferenceElement
128
137
}
129
138
130
139
export interface PopperContentContext {
@@ -140,7 +149,7 @@ export const [injectPopperContentContext, providePopperContentContext]
140
149
</script >
141
150
142
151
<script setup lang="ts">
143
- import { computed , ref , watchEffect } from ' vue'
152
+ import { computed , ref , toRefs , watchEffect } from ' vue'
144
153
import { computedEager } from ' @vueuse/core'
145
154
import {
146
155
autoUpdate ,
@@ -173,8 +182,8 @@ const props = withDefaults(defineProps<PopperContentProps>(), {
173
182
const emits = defineEmits <{
174
183
placed: [void ]
175
184
}>()
176
- const rootContext = injectPopperRootContext ()
177
185
186
+ const rootContext = injectPopperRootContext ()
178
187
const { forwardRef, currentElement : contentElement } = useForwardExpose ()
179
188
180
189
const floatingRef = ref <HTMLElement >()
@@ -270,8 +279,11 @@ const computedMiddleware = computedEager(() => {
270
279
] as Middleware []
271
280
})
272
281
282
+ // If provided custom reference, it will overwrite the defautl anchor element
283
+ const reference = computed (() => props .reference ?? rootContext .anchor .value )
284
+
273
285
const { floatingStyles, placement, isPositioned, middlewareData } = useFloating (
274
- rootContext . anchor ,
286
+ reference ,
275
287
floatingRef ,
276
288
{
277
289
strategy: ' fixed' ,
0 commit comments