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

[bug]: useResize uses content box instead of border box #2288

Open
1 of 5 tasks
LoganDark opened this issue Jun 7, 2024 · 0 comments
Open
1 of 5 tasks

[bug]: useResize uses content box instead of border box #2288

LoganDark opened this issue Jun 7, 2024 · 0 comments
Labels
template: bug This issue might be a bug

Comments

@LoganDark
Copy link
Contributor

LoganDark commented Jun 7, 2024

Which react-spring target are you using?

  • @react-spring/web
  • @react-spring/three
  • @react-spring/native
  • @react-spring/konva
  • @react-spring/zdog

What version of react-spring are you using?

9.7.3

What's Wrong?

useResize returns the size of the content box, without padding or borders. It should use the border box instead.

if (observer) {
observer.observe(target)
}

-   if (observer) {
-     observer.observe(target)
-   }
+   observer?.observe(target, { box: 'border-box' })

const handleObservation = (entries: ResizeObserverEntry[]) =>
entries.forEach(({ target, contentRect }) => {
return resizeHandlers.get(target)?.forEach(handler => handler(contentRect))
})

 const handleObservation = (entries: ResizeObserverEntry[]) =>
-  entries.forEach(({ target, contentRect }) => {
-    return resizeHandlers.get(target)?.forEach(handler => handler(contentRect))
+  entries.forEach(({ target, borderBoxSize }) => {
+    const handlers = resizeHandlers.get(target)
+    if (!handlers) return
+    const { blockSize, inlineSize } = borderBoxSize[0]
+    const { width, height } = !getComputedStyle(target).getPropertyValue('writing-mode')?.startsWith('vertical-')
+      ? { width: inlineSize, height: blockSize }
+      : { width: blockSize, height: inlineSize }
+    for (const handler of handlers) handler({ width, height })
   })

MDN

To Reproduce

observe an element that has padding.

Expected Behaviour

padding should be included in the returned size.

Link to repo

https://codesandbox.io/p/sandbox/muddy-hill-sjfzwl

@LoganDark LoganDark added the template: bug This issue might be a bug label Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
template: bug This issue might be a bug
Projects
None yet
Development

No branches or pull requests

1 participant