jaredLunde/react-hook

[useResizeObserver] Use border-box instead of content-box

bhollis opened this issue · 4 comments

Is your feature request related to a problem? Please describe.

getBoundingClientRect returns the border-box, which includes padding and borders. However by default ResizeObserver.observe uses the content-box, which does not. This renders the example for useResizeObserver incorrect as it'll set the size with padding, then update to the size without padding. useSize avoids this by using offsetWidth and offsetHeight.

Describe the solution you'd like

Either pass the content-box option to ResizeObserver.observe, or change the example in the README to not use getBoundingClientRect.

Describe alternatives you've considered
I just switched to reading offsetHeight like useSize does.

afaik border-box is experimental and not widely supported. if you can show me something showing it has wide support, by all means.

If ResizeObserver.observe's options parameter is not widely supported, then the solution would be to update the example in the README to use offsetWidth and offsetHeight instead of getBoundingContentRect.

feel free to update the README, I personally see nothing inaccurate about it.

isc30 commented

@bhollis is right, the example uses the BoundingClientRect (border-box) for the initial size and later on the resize handler it uses the contentRect (content-box)