Skip to content

Commit 9f2e861

Browse files
authored
fix: make grid with all rows vIsible respect max height (#5429)
1 parent 0eddcdf commit 9f2e861

2 files changed

Lines changed: 76 additions & 2 deletions

File tree

‎packages/grid/src/vaadin-grid-styles.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ registerStyles(
1515
}
1616
1717
:host {
18-
display: block;
18+
display: flex;
19+
flex-direction: column;
1920
animation: 1ms vaadin-grid-appear;
2021
height: 400px;
2122
flex: 1 1 auto;
@@ -32,7 +33,9 @@ registerStyles(
3233
}
3334
3435
#scroller {
35-
display: block;
36+
display: flex;
37+
flex-direction: column;
38+
min-height: 100%;
3639
transform: translateY(0);
3740
width: auto;
3841
height: auto;

‎packages/grid/test/resizing.test.js‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { expect } from '@esm-bundle/chai';
22
import { aTimeout, fixtureSync, nextFrame, oneEvent } from '@vaadin/testing-helpers';
3+
import sinon from 'sinon';
34
import '../vaadin-grid.js';
45
import '../vaadin-grid-column-group.js';
56
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
67
import {
78
flushGrid,
89
getContainerCellContent,
910
getHeaderCellContent,
11+
getLastVisibleItem,
1012
getPhysicalItems,
1113
getRowCells,
1214
getRows,
@@ -213,4 +215,73 @@ describe('all rows visible', () => {
213215
expect(getPhysicalItems(grid).length).to.be.above(0);
214216
});
215217
});
218+
219+
describe('max-height', () => {
220+
let wrapper;
221+
222+
beforeEach(() => {
223+
wrapper = fixtureSync(`
224+
<div>
225+
<vaadin-grid>
226+
<vaadin-grid-column path="value"></vaadin-grid-column>
227+
</vaadin-grid>
228+
</div>
229+
`);
230+
grid = wrapper.firstElementChild;
231+
grid.allRowsVisible = true;
232+
grid.style.maxHeight = '300px';
233+
grid.items = [...Array(100)].map((_, idx) => ({ value: idx }));
234+
grid.dataProvider = sinon.spy(grid.dataProvider);
235+
flushGrid(grid);
236+
});
237+
238+
it('should include rows', () => {
239+
const lastRowRect = getLastVisibleItem(grid).getBoundingClientRect();
240+
const gridRect = grid.getBoundingClientRect();
241+
expect(lastRowRect.top).to.be.below(gridRect.bottom);
242+
expect(lastRowRect.bottom).to.be.above(gridRect.bottom);
243+
});
244+
245+
it('should not overflow rows', () => {
246+
const gridRect = grid.getBoundingClientRect();
247+
const belowGrid = document.elementFromPoint(gridRect.left + 1, gridRect.bottom + 1);
248+
expect(grid.contains(belowGrid)).to.be.false;
249+
});
250+
251+
it('should not grow beyond max-height', () => {
252+
expect(grid.getBoundingClientRect().height).to.equal(300);
253+
});
254+
255+
it('should shrink below max-height', () => {
256+
grid.items = [{ value: 0 }];
257+
flushGrid(grid);
258+
expect(grid.getBoundingClientRect().height).to.be.below(100);
259+
});
260+
261+
it('should have requested first page initially', () => {
262+
const calls = grid.dataProvider.getCalls();
263+
expect(calls.some((call) => call.firstArg.page === 0)).to.be.true;
264+
});
265+
266+
it('should not have requested second page initially', () => {
267+
const calls = grid.dataProvider.getCalls();
268+
expect(calls.some((call) => call.firstArg.page === 1)).to.be.false;
269+
});
270+
271+
it('should request second page when max-height is reset', () => {
272+
grid.style.maxHeight = '';
273+
flushGrid(grid);
274+
const calls = grid.dataProvider.getCalls();
275+
expect(calls.some((call) => call.firstArg.page === 1)).to.be.true;
276+
});
277+
278+
it('should not overflow rows when using relative max-height', () => {
279+
wrapper.style.height = '600px';
280+
grid.style.maxHeight = '50%';
281+
282+
const gridRect = grid.getBoundingClientRect();
283+
const belowGrid = document.elementFromPoint(gridRect.left + 1, gridRect.bottom + 1);
284+
expect(grid.contains(belowGrid)).to.be.false;
285+
});
286+
});
216287
});

0 commit comments

Comments
 (0)