Skip to content

Commit

Permalink
fix: DOMRect value issues
Browse files Browse the repository at this point in the history
  • Loading branch information
consistent-k committed Aug 30, 2024
1 parent 7984a14 commit ad3d5e6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/hooks/useAlign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ export default function useAlign(
};
} else {
const rect = target.getBoundingClientRect();
rect.x = rect.x || rect.left;
rect.y = rect.y || rect.top

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (99% of all statements in
the enclosing function
have an explicit semicolon).
targetRect = {
x: rect.x || rect.left,
y: rect.y || rect.top,
x: rect.x,
y: rect.y,
width: rect.width,
height: rect.height,
};
Expand Down
2 changes: 2 additions & 0 deletions tests/align.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ describe('Trigger.Align', () => {
getBoundingClientRect: () => ({
x: rectX,
y: rectY,
left: rectX,
top: rectY,
width: rectWidth,
height: rectHeight,
right: 200,
Expand Down
2 changes: 2 additions & 0 deletions tests/arrow.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ describe('Trigger.Arrow', () => {
() => ({
x: 200,
y: 200,
left: 200,
top: 200,
width: 100,
height: 50,
}),
Expand Down
12 changes: 12 additions & 0 deletions tests/flip-visibleFirst.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,26 @@ describe('Trigger.VisibleFirst', () => {
let containerRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 100,
height: 100,
};

let targetRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 1,
height: 1,
};

let popupRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 100,
height: 100,
};
Expand All @@ -84,18 +90,24 @@ describe('Trigger.VisibleFirst', () => {
containerRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 100,
height: 100,
};
targetRect = {
x: 250,
y: 250,
left: 250,
top: 250,
width: 1,
height: 1,
};
popupRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 100,
height: 100,
};
Expand Down
14 changes: 14 additions & 0 deletions tests/flip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ describe('Trigger.Align', () => {
let spanRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 1,
height: 1,
};

let popupRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 100,
height: 100,
};
Expand Down Expand Up @@ -112,12 +116,16 @@ describe('Trigger.Align', () => {
spanRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 1,
height: 1,
};
popupRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 100,
height: 100,
};
Expand Down Expand Up @@ -253,6 +261,8 @@ describe('Trigger.Align', () => {
popupRect = {
x: 100,
y: 1,
left: 100,
top: 1,
width: 100,
height: 100,
};
Expand Down Expand Up @@ -339,6 +349,8 @@ describe('Trigger.Align', () => {
({
x: 100,
y: 100,
left: 100,
top: 100,
width: 300,
height: 300,
} as any);
Expand Down Expand Up @@ -384,6 +396,8 @@ describe('Trigger.Align', () => {
popupRect = {
x: 0,
y: 0,
left: 0,
top: 0,
width: 200,
height: 200,
};
Expand Down
6 changes: 5 additions & 1 deletion tests/flipShift.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ const builtinPlacements = {
};

describe('Trigger.Flip+Shift', () => {
let spanRect = { x: 0, y: 0, width: 0, height: 0 };
let spanRect = { x: 0, y: 0, left: 0, top: 0, width: 0, height: 0 };

beforeEach(() => {
spanRect = {
x: 0,
y: 100,
left: 0,
top: 100,
width: 100,
height: 100,
};
Expand Down Expand Up @@ -113,6 +115,8 @@ describe('Trigger.Flip+Shift', () => {
return {
x: 0,
y: 0,
left: 0,
top: 0,
width: 100,
height: 300,
};
Expand Down

0 comments on commit ad3d5e6

Please sign in to comment.