Skip to content

Commit b22479b

Browse files
Artur-claude
andcommitted
feat: update grid min-height calculation to include header/footer slots
The min-height calculation now accounts for header and footer slot content in addition to the existing table headers/footers and default row height. This ensures the grid maintains proper sizing when using the new header and footer slot functionality. - Observe header and footer slot containers with ResizeObserver - Include slot container heights in min-height calculation - Add comprehensive tests for slot-based min-height scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 38647c9 commit b22479b

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

packages/grid/src/vaadin-grid-mixin.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,9 @@ export const GridMixin = (superClass) =>
278278
minHeightObserver.observe(this.$.header);
279279
minHeightObserver.observe(this.$.items);
280280
minHeightObserver.observe(this.$.footer);
281+
// Also observe the header and footer slot containers
282+
minHeightObserver.observe(this.$.gridHeader);
283+
minHeightObserver.observe(this.$.gridFooter);
281284

282285
this._tooltipController = new TooltipController(this);
283286
this.addController(this._tooltipController);
@@ -958,7 +961,12 @@ export const GridMixin = (superClass) =>
958961
const headerHeight = this.$.header.clientHeight;
959962
const footerHeight = this.$.footer.clientHeight;
960963
const scrollbarHeight = this.$.table.offsetHeight - this.$.table.clientHeight;
961-
const minHeight = headerHeight + rowHeight + footerHeight + scrollbarHeight;
964+
965+
// Include header and footer slot container heights
966+
const headerSlotHeight = this.$.gridHeader.clientHeight;
967+
const footerSlotHeight = this.$.gridFooter.clientHeight;
968+
969+
const minHeight = headerHeight + rowHeight + footerHeight + scrollbarHeight + headerSlotHeight + footerSlotHeight;
962970

963971
// The style is set to host instead of the scroller so that the value can be overridden by the user with "grid { min-height: 0 }"
964972
// Prefer setting style in adopted style sheet to avoid the need to add a confusing inline style on the host element

packages/grid/test/min-height.test.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,72 @@ describe('min-height', () => {
101101
});
102102
});
103103

104+
describe('with header slot', () => {
105+
beforeEach(async () => {
106+
const headerDiv = document.createElement('div');
107+
headerDiv.setAttribute('slot', 'header');
108+
headerDiv.style.height = '50px';
109+
headerDiv.textContent = 'Header Slot Content';
110+
grid.appendChild(headerDiv);
111+
flushGrid(grid);
112+
await nextResize(grid);
113+
});
114+
115+
it('should include header slot height in min-height', () => {
116+
const height = grid.getBoundingClientRect().height;
117+
const headerSlotHeight = grid.shadowRoot.querySelector('#gridHeader').getBoundingClientRect().height;
118+
expect(headerSlotHeight).to.be.above(0);
119+
expect(height).to.be.at.least(rowHeight + headerSlotHeight);
120+
});
121+
});
122+
123+
describe('with footer slot', () => {
124+
beforeEach(async () => {
125+
const footerDiv = document.createElement('div');
126+
footerDiv.setAttribute('slot', 'footer');
127+
footerDiv.style.height = '40px';
128+
footerDiv.textContent = 'Footer Slot Content';
129+
grid.appendChild(footerDiv);
130+
flushGrid(grid);
131+
await nextResize(grid);
132+
});
133+
134+
it('should include footer slot height in min-height', () => {
135+
const height = grid.getBoundingClientRect().height;
136+
const footerSlotHeight = grid.shadowRoot.querySelector('#gridFooter').getBoundingClientRect().height;
137+
expect(footerSlotHeight).to.be.above(0);
138+
expect(height).to.be.at.least(rowHeight + footerSlotHeight);
139+
});
140+
});
141+
142+
describe('with header and footer slots', () => {
143+
beforeEach(async () => {
144+
const headerDiv = document.createElement('div');
145+
headerDiv.setAttribute('slot', 'header');
146+
headerDiv.style.height = '50px';
147+
headerDiv.textContent = 'Header Slot Content';
148+
grid.appendChild(headerDiv);
149+
150+
const footerDiv = document.createElement('div');
151+
footerDiv.setAttribute('slot', 'footer');
152+
footerDiv.style.height = '40px';
153+
footerDiv.textContent = 'Footer Slot Content';
154+
grid.appendChild(footerDiv);
155+
156+
flushGrid(grid);
157+
await nextResize(grid);
158+
});
159+
160+
it('should include both header and footer slot heights in min-height', () => {
161+
const height = grid.getBoundingClientRect().height;
162+
const headerSlotHeight = grid.shadowRoot.querySelector('#gridHeader').getBoundingClientRect().height;
163+
const footerSlotHeight = grid.shadowRoot.querySelector('#gridFooter').getBoundingClientRect().height;
164+
expect(headerSlotHeight).to.be.above(0);
165+
expect(footerSlotHeight).to.be.above(0);
166+
expect(height).to.be.at.least(rowHeight + headerSlotHeight + footerSlotHeight);
167+
});
168+
});
169+
104170
describe('override', () => {
105171
beforeEach(() => {
106172
fixtureSync(`

0 commit comments

Comments
 (0)