Skip to content

Commit 2cd8402

Browse files
authored
Fix ResizeObserver being used even with size provided (#855)
1 parent e83054b commit 2cd8402

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

lib/components/grid/Grid.test.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
44
import { EMPTY_OBJECT } from "../../../src/constants";
55
import {
66
disableForCurrentTest,
7+
simulateUnsupportedEnvironmentForTest,
78
updateMockResizeObserver
89
} from "../../utils/test/mockResizeObserver";
910
import { Grid } from "./Grid";
@@ -579,6 +580,26 @@ describe("Grid", () => {
579580

580581
render(<Test />);
581582
});
583+
584+
test("should not require ResizeObserver if size is provided", () => {
585+
const originalResizeObserver = window.ResizeObserver;
586+
simulateUnsupportedEnvironmentForTest();
587+
588+
render(
589+
<Grid
590+
cellComponent={CellComponent}
591+
cellProps={EMPTY_OBJECT}
592+
columnCount={100}
593+
columnWidth={25}
594+
overscanCount={2}
595+
rowCount={100}
596+
rowHeight={20}
597+
style={{ height: 42, width: 84 }}
598+
/>
599+
);
600+
601+
window.ResizeObserver = originalResizeObserver;
602+
});
582603
});
583604

584605
describe("aria attributes", () => {

lib/components/grid/Grid.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function Grid<
5757
stopIndexVisible: columnStopIndexVisible
5858
} = useVirtualizer({
5959
containerElement: element,
60+
containerStyle: style,
6061
defaultContainerSize: defaultWidth,
6162
direction: "horizontal",
6263
isRtl,
@@ -77,6 +78,7 @@ export function Grid<
7778
stopIndexVisible: rowStopIndexVisible
7879
} = useVirtualizer({
7980
containerElement: element,
81+
containerStyle: style,
8082
defaultContainerSize: defaultHeight,
8183
direction: "vertical",
8284
itemCount: rowCount,

lib/components/list/List.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest";
44
import { EMPTY_OBJECT } from "../../../src/constants";
55
import {
66
disableForCurrentTest,
7+
simulateUnsupportedEnvironmentForTest,
78
updateMockResizeObserver
89
} from "../../utils/test/mockResizeObserver";
910
import { List } from "./List";
@@ -685,6 +686,22 @@ describe("List", () => {
685686

686687
render(<Test />);
687688
});
689+
690+
test("should not require ResizeObserver if height is provided", () => {
691+
const originalResizeObserver = window.ResizeObserver;
692+
simulateUnsupportedEnvironmentForTest();
693+
render(
694+
<List
695+
overscanCount={0}
696+
rowCount={100}
697+
rowComponent={RowComponent}
698+
rowHeight={25}
699+
rowProps={EMPTY_OBJECT}
700+
style={{ height: 42 }}
701+
/>
702+
);
703+
window.ResizeObserver = originalResizeObserver;
704+
});
688705
});
689706

690707
describe("aria attributes", () => {

lib/components/list/List.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export function List<
5050
stopIndexVisible
5151
} = useVirtualizer({
5252
containerElement: element,
53+
containerStyle: style,
5354
defaultContainerSize: defaultHeight,
5455
direction: "vertical",
5556
itemCount: rowCount,

0 commit comments

Comments
 (0)