Skip to content

Commit 99ca82e

Browse files
authored
Fix calculatePosition types and tests (#4729)
1 parent 9883fdb commit 99ca82e

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

packages/@react-aria/overlays/src/calculatePosition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
393393
offset,
394394
crossOffset,
395395
maxHeight,
396-
arrowSize,
396+
arrowSize = 0,
397397
arrowBoundaryOffset = 0
398398
} = opts;
399399

packages/@react-aria/overlays/test/calculatePosition.test.js renamed to packages/@react-aria/overlays/test/calculatePosition.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ const containerDimensions = {
3838
};
3939

4040
// Reset JSDom's default margin on the body
41-
document.body.style.margin = 0;
41+
document.body.style.margin = '0';
4242

43-
function createElementWithDimensions(elemName, dimensions, margins) {
44-
margins = margins || {};
43+
function createElementWithDimensions(elemName, dimensions, margins = {}) {
4544
let elem = document.createElement(elemName);
4645

4746
Object.assign(elem.style, {
@@ -103,7 +102,7 @@ describe('calculatePosition', function () {
103102
const placementAxis = placement.split(' ')[0];
104103

105104
// The tests are all based on top/left positioning. Convert to bottom/right positioning if needed.
106-
let pos = {};
105+
let pos: {right?: number, top?: number, left?: number, bottom?: number} = {};
107106
if ((placementAxis === 'left' && !flip) || (placementAxis === 'right' && flip)) {
108107
pos.right = boundaryDimensions.width - (expected[0] + overlaySize.width);
109108
pos.top = expected[1];
@@ -164,7 +163,7 @@ describe('calculatePosition', function () {
164163
});
165164
}
166165

167-
function checkPosition(placement, targetDimension, expected, offset = 0, crossOffset = 0, flip = false, providerOffset, arrowSize, arrowBoundaryOffset) {
166+
function checkPosition(placement, targetDimension, expected, offset = 0, crossOffset = 0, flip = false, providerOffset = undefined, arrowSize = undefined, arrowBoundaryOffset = undefined) {
168167
checkPositionCommon(
169168
'Should calculate the correct position',
170169
expected,
@@ -396,7 +395,7 @@ describe('calculatePosition', function () {
396395
const overlayNode = document.createElement('div');
397396
const container = document.createElement('div');
398397

399-
target.style = 'margin:20px';
398+
target.style.margin = '20px';
400399
document.body.appendChild(target);
401400

402401
let {position: {top: positionTop}} = calculatePosition({
@@ -408,7 +407,8 @@ describe('calculatePosition', function () {
408407
shouldFlip: false,
409408
boundaryElement: container,
410409
offset: 0,
411-
crossOffset: 0
410+
crossOffset: 0,
411+
arrowSize: 0
412412
});
413413
expect(positionTop).toBe(0);
414414

packages/@react-aria/overlays/test/useOverlayPosition.test.js renamed to packages/@react-aria/overlays/test/useOverlayPosition.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Example({triggerTop = 250, ...props}) {
1818
let targetRef = useRef();
1919
let containerRef = useRef();
2020
let overlayRef = useRef();
21-
let {overlayProps, placement, arrowProps} = useOverlayPosition({targetRef, containerRef, overlayRef, arrowSize: 8, ...props});
21+
let {overlayProps, placement, arrowProps} = useOverlayPosition({targetRef, overlayRef, arrowSize: 8, ...props});
2222
let style = {width: 300, height: 200, ...overlayProps.style};
2323
return (
2424
<React.Fragment>
@@ -33,12 +33,15 @@ function Example({triggerTop = 250, ...props}) {
3333
);
3434
}
3535

36+
// @ts-ignore
3637
HTMLElement.prototype.getBoundingClientRect = function () {
3738
return {
3839
left: parseInt(this.style.left, 10) || 0,
3940
top: parseInt(this.style.top, 10) || 0,
41+
right: parseInt(this.style.right, 10) || 0,
42+
bottom: parseInt(this.style.bottom, 10) || 0,
4043
width: parseInt(this.style.width, 10) || 0,
41-
height: parseInt(this.style.width, 10) || 0
44+
height: parseInt(this.style.height, 10) || 0
4245
};
4346
};
4447

0 commit comments

Comments
 (0)