Skip to content

Commit

Permalink
fix(Popper): position not updating when reference changes
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed Aug 13, 2024
1 parent 82505dc commit cd3f1eb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/core/src/Popper/PopperContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export const [injectPopperContentContext, providePopperContentContext]

<script setup lang="ts">
import { computed, ref, watchEffect } from 'vue'
import { computedEager } from '@vueuse/core'
import { computedEager, useThrottleFn } from '@vueuse/core'
import {
autoUpdate,
flip,
Expand Down Expand Up @@ -291,7 +291,7 @@ const computedMiddleware = computedEager(() => {
// If provided custom reference, it will overwrite the defautl anchor element
const reference = computed(() => props.reference ?? rootContext.anchor.value)
const { floatingStyles, placement, isPositioned, middlewareData } = useFloating(
const { floatingStyles, placement, isPositioned, middlewareData, update } = useFloating(
reference,
floatingRef,
{
Expand Down Expand Up @@ -320,6 +320,14 @@ watchEffect(() => {
emits('placed')
})
// update position automatically when `boundingClientRect` changes
const throttleUpdate = useThrottleFn(update, 10, true, true)
watchEffect(() => {
if (reference.value?.getBoundingClientRect()) {
throttleUpdate()
}
})
const cannotCenterArrow = computed(
() => middlewareData.value.arrow?.centerOffset !== 0,
)
Expand Down

0 comments on commit cd3f1eb

Please # to comment.