Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[useElementBounding]: doesn't update bounding box on scroll #626

Closed
jeffrey-dot-li opened this issue Jul 16, 2021 · 4 comments · Fixed by #1541
Closed

[useElementBounding]: doesn't update bounding box on scroll #626

jeffrey-dot-li opened this issue Jul 16, 2021 · 4 comments · Fixed by #1541

Comments

@jeffrey-dot-li
Copy link
Contributor

I'm a bit confused about what useElementBounding is supposed to do but if it is supposed to mirror getBoundingClientRect like it says in the docs then it should update the properties such as top and y relative to the viewport scroll like the example in the mozilla documentation:
image
image

Currently bounding box doesnt change on scroll
image
image

@jeffrey-dot-li
Copy link
Contributor Author

Maybe this isn't what element bounding is intended for? In that case, can we add a hook for getBoundingClientRect similar to what is used in useMouseInElement?

} = el.getBoundingClientRect()

@pwang2
Copy link

pwang2 commented Feb 3, 2022

I also feel it is weird to not have a BCR reactive to resizing, scrolling. I managed to get it work as below, but feel not very satisfied.

import { useElementBounding, useResizeObserver } from "@vueuse/core"
const triggerRect = reactive(useElementBounding(trigger))
useResizeObserver(document.documentElement, () => {
  Object.assign(triggerRect, useElementBounding(trigger))
})```

@m0dch3n
Copy link

m0dch3n commented Feb 4, 2022

not sure, if this is related too, but

const mydiv = ref()
const { width } = useElementBounding(mydiv)
onMounted(() => {
  console.log('div', mydiv.value) // the div is consoled
  console.log('width value', width.value) // is still 0
  console.log('width clientrect', mydiv.value.getBoundingClientRect().width) // is correct width
  setTimeout(() => {
    console.log('width value 3', width.value) // is correct width value...
  })
})

The dimensions should be available onMounted....

Hebilicious added a commit to Hebilicious/vueuse that referenced this issue Apr 29, 2022
- Call update on compoment mounted
- Add a flag to disable that behaviour
- Default it to true to return the correct values immediately
@Hebilicious
Copy link
Contributor

@m0dch3n Had the same issue, #1541 fixes it 👍🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants