Skip to content

Commit d847036

Browse files
authored
Fix: DOMLayoutDelegate miscalculates item & visible rects (#8696)
* fix: subtract border width from visible rect * fix: tests * fix: table tests * fix: adjust item rects by container border * fix: item rect calculation * feat: simplify rect calculation * fix: remove scroll position from offset * fix: typo * fix: calculate position relative to viewport * fix: container relative calc * chore: formatting
1 parent 23e4a2d commit d847036

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

packages/@react-aria/dnd/test/useDroppableCollection.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('useDroppableCollection', () => {
5656
return this.getBoundingClientRect().top;
5757
});
5858

59-
jest.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockImplementation(function () {
59+
jest.spyOn(HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(function () {
6060
return this.getBoundingClientRect().height;
6161
});
6262

packages/@react-aria/selection/src/DOMLayoutDelegate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export class DOMLayoutDelegate implements LayoutDelegate {
3434
let itemRect = item.getBoundingClientRect();
3535

3636
return {
37-
x: itemRect.left - containerRect.left + container.scrollLeft,
38-
y: itemRect.top - containerRect.top + container.scrollTop,
37+
x: itemRect.left - containerRect.left - container.clientLeft + container.scrollLeft,
38+
y: itemRect.top - containerRect.top - container.clientTop + container.scrollTop,
3939
width: itemRect.width,
4040
height: itemRect.height
4141
};
@@ -54,8 +54,8 @@ export class DOMLayoutDelegate implements LayoutDelegate {
5454
return {
5555
x: container?.scrollLeft ?? 0,
5656
y: container?.scrollTop ?? 0,
57-
width: container?.offsetWidth ?? 0,
58-
height: container?.offsetHeight ?? 0
57+
width: container?.clientWidth ?? 0,
58+
height: container?.clientHeight ?? 0
5959
};
6060
}
6161
}

packages/react-aria-components/test/Table.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,15 +1633,15 @@ describe('Table', () => {
16331633
});
16341634

16351635
describe('load more spinner', () => {
1636-
let offsetHeight, scrollHeight;
1636+
let clientHeight, scrollHeight;
16371637
let DndTable = stories.DndTable;
16381638
let initialItems = [
16391639
{id: '1', type: 'file', name: 'Adobe Photoshop'},
16401640
{id: '2', type: 'file', name: 'Adobe XD'}
16411641
];
16421642
beforeAll(function () {
16431643
scrollHeight = jest.spyOn(window.HTMLElement.prototype, 'scrollHeight', 'get').mockImplementation(() => 200);
1644-
offsetHeight = jest.spyOn(window.HTMLElement.prototype, 'offsetHeight', 'get').mockImplementation(function () {
1644+
clientHeight = jest.spyOn(window.HTMLElement.prototype, 'clientHeight', 'get').mockImplementation(function () {
16451645
if (this.getAttribute('role') === 'grid') {
16461646
return 200;
16471647
}
@@ -1651,7 +1651,7 @@ describe('Table', () => {
16511651
});
16521652

16531653
afterAll(function () {
1654-
offsetHeight.mockReset();
1654+
clientHeight.mockReset();
16551655
scrollHeight.mockReset();
16561656
});
16571657

0 commit comments

Comments
 (0)