Skip to content

Commit

Permalink
chore: all width
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Oct 16, 2023
1 parent b3fc83f commit fc31b64
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const getTabSize = (tab: HTMLElement, containerRect: { x: number; y: number }) =
const { offsetWidth, offsetHeight, offsetTop, offsetLeft } = tab;
const { width, height, x, y } = tab.getBoundingClientRect();

// Use getBoundingClientRect to avoid decimal inaccuracy
if (Math.abs(width - offsetWidth) < 1) {
return [width, height, x - containerRect.x, y - containerRect.y];
}
Expand All @@ -67,6 +68,16 @@ const getTabSize = (tab: HTMLElement, containerRect: { x: number; y: number }) =

const getSize = (refObj: React.RefObject<HTMLElement>): SizeInfo => {
const { offsetWidth = 0, offsetHeight = 0 } = refObj.current || {};

// Use getBoundingClientRect to avoid decimal inaccuracy
if (refObj.current) {
const { width, height } = refObj.current.getBoundingClientRect();

if (Math.abs(width - offsetWidth) < 1) {
return [width, height];
}
}

return [offsetWidth, offsetHeight];
};

Expand Down

0 comments on commit fc31b64

Please sign in to comment.