Skip to content

Commit 4ffc644

Browse files
authored
fixing virtualizer hasLayoutUpdates check for width/height change cases (adobe#2028)
tableview row width was not updating properly when the 2nd to last column was removed because we were not detecting the width change
1 parent 6924b49 commit 4ffc644

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

packages/@react-spectrum/table/test/Table.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,6 +3809,57 @@ describe('TableView', function () {
38093809
expect(within(row).getAllByRole('gridcell')).toHaveLength(5);
38103810
}
38113811
});
3812+
3813+
it('should update the row widths when removing and adding columns', function () {
3814+
function compareWidths(row, b) {
3815+
let newWidth = row.childNodes[1].style.width;
3816+
expect(parseInt(newWidth, 10)).toBeGreaterThan(parseInt(b, 10));
3817+
return newWidth;
3818+
}
3819+
3820+
let tree = render(<HidingColumns />);
3821+
let table = tree.getByRole('grid');
3822+
let columns = within(table).getAllByRole('columnheader');
3823+
expect(columns).toHaveLength(6);
3824+
3825+
let rows = tree.getAllByRole('row');
3826+
let oldWidth = rows[1].childNodes[1].style.width;
3827+
3828+
let audienceCheckbox = tree.getByLabelText('Audience Type');
3829+
let budgetCheckbox = tree.getByLabelText('Net Budget');
3830+
let targetCheckbox = tree.getByLabelText('Target OTP');
3831+
let reachCheckbox = tree.getByLabelText('Reach');
3832+
3833+
userEvent.click(audienceCheckbox);
3834+
expect(audienceCheckbox.checked).toBe(false);
3835+
act(() => jest.runAllTimers());
3836+
oldWidth = compareWidths(rows[1], oldWidth);
3837+
3838+
userEvent.click(budgetCheckbox);
3839+
expect(budgetCheckbox.checked).toBe(false);
3840+
act(() => jest.runAllTimers());
3841+
oldWidth = compareWidths(rows[1], oldWidth);
3842+
3843+
userEvent.click(targetCheckbox);
3844+
expect(targetCheckbox.checked).toBe(false);
3845+
act(() => jest.runAllTimers());
3846+
oldWidth = compareWidths(rows[1], oldWidth);
3847+
3848+
// This previously failed, the first column wouldn't update its width
3849+
// when the 2nd to last column was removed
3850+
userEvent.click(reachCheckbox);
3851+
expect(reachCheckbox.checked).toBe(false);
3852+
act(() => jest.runAllTimers());
3853+
oldWidth = compareWidths(rows[1], oldWidth);
3854+
columns = within(table).getAllByRole('columnheader');
3855+
expect(columns).toHaveLength(2);
3856+
3857+
// Readd the column and check that the width decreases
3858+
userEvent.click(audienceCheckbox);
3859+
expect(audienceCheckbox.checked).toBe(true);
3860+
act(() => jest.runAllTimers());
3861+
expect(parseInt(rows[1].childNodes[1].style.width, 10)).toBeLessThan(parseInt(oldWidth, 10));
3862+
});
38123863
});
38133864

38143865
describe('headerless columns', function () {

packages/@react-stately/virtualizer/src/Virtualizer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ export class Virtualizer<T extends object, V, W> {
867867

868868
let layoutInfo = this.layout.getLayoutInfo(cur.key);
869869
if (
870-
!cur.rect.pointEquals(layoutInfo.rect) ||
870+
// Uses equals rather than pointEquals so that width/height changes are taken into account
871+
!cur.rect.equals(layoutInfo.rect) ||
871872
cur.opacity !== layoutInfo.opacity ||
872873
cur.transform !== layoutInfo.transform
873874
) {

0 commit comments

Comments
 (0)