From c66a61a309bd838e2f076de2cc7e180984311d09 Mon Sep 17 00:00:00 2001 From: Alex Kolpa Date: Thu, 12 Dec 2019 14:12:39 +0100 Subject: [PATCH] Ensure rect is rounded correctly This fixes a bug introduced in joshwnj/react-visibility-sensor#116, which introduced rounding on the element rect. When a `containment` is specified that itself has non-integer values in its bounding rect, you get a rounding issue as `top` and `left` will be floored, causing them to go out of the containment bounding rect. Say you have a container element with `left: 100.5` and the element rect at `left: 100.5` as well; this then gets rounded down to `left: 100`, meaning it is no longer considered completely visible. --- visibility-sensor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/visibility-sensor.js b/visibility-sensor.js index 067b3c4..a9c7990 100644 --- a/visibility-sensor.js +++ b/visibility-sensor.js @@ -208,8 +208,8 @@ export default class VisibilitySensor extends React.Component { roundRectDown(rect) { return { - top: Math.floor(rect.top), - left: Math.floor(rect.left), + top: Math.ceil(rect.top), + left: Math.ceil(rect.left), bottom: Math.floor(rect.bottom), right: Math.floor(rect.right) };