From 9b832d4bf472549f704c5afa35dc8b788dc0757e Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Tue, 14 Jan 2020 10:39:59 +0100 Subject: [PATCH] Fixes values of top and left which are inverted `top` value should correspond to the `y` value, not the `x` value. This PR fix this and remove duplication. --- src/index.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5fc60eb..45ae839 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,14 +3,15 @@ import { DimensionObject, UseDimensionsArgs, UseDimensionsHook } from "./types"; function getDimensionObject(node: HTMLElement): DimensionObject { const rect = node.getBoundingClientRect(); - + const left = "x" in rect ? rect.x : rect.left; + const top = "y" in rect ? rect.y : rect.top; return { width: rect.width, height: rect.height, - top: "x" in rect ? rect.x : rect.top, - left: "y" in rect ? rect.y : rect.left, - x: "x" in rect ? rect.x : rect.left, - y: "y" in rect ? rect.y : rect.top, + x: left, + y: top, + top: top, + left: left, right: rect.right, bottom: rect.bottom };