Skip to content

Commit 53e8594

Browse files
authored
feat: add dedicated CSS parts for header and footer rows (#10449)
1 parent 10d7c35 commit 53e8594

File tree

5 files changed

+532
-79
lines changed

5 files changed

+532
-79
lines changed

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
iterateRowCells,
2929
updateBooleanRowStates,
3030
updateCellsPart,
31+
updatePart,
3132
updateState,
3233
} from './vaadin-grid-helpers.js';
3334
import { KeyboardNavigationMixin } from './vaadin-grid-keyboard-navigation-mixin.js';
@@ -641,10 +642,12 @@ export const GridMixin = (superClass) =>
641642

642643
if (row.parentElement === this.$.header) {
643644
this.$.table.toggleAttribute('has-header', this.$.header.querySelector('tr:not([hidden])'));
645+
this.__updateHeaderFooterRowParts('header');
644646
}
645647

646648
if (row.parentElement === this.$.footer) {
647649
this.$.table.toggleAttribute('has-footer', this.$.footer.querySelector('tr:not([hidden])'));
650+
this.__updateHeaderFooterRowParts('footer');
648651
}
649652

650653
// Make sure the section has a tabbable element
@@ -710,13 +713,13 @@ export const GridMixin = (superClass) =>
710713

711714
while (this.$.header.children.length < columnTree.length) {
712715
const headerRow = document.createElement('tr');
713-
headerRow.setAttribute('part', 'row');
716+
headerRow.setAttribute('part', 'row header-row');
714717
headerRow.setAttribute('role', 'row');
715718
headerRow.setAttribute('tabindex', '-1');
716719
this.$.header.appendChild(headerRow);
717720

718721
const footerRow = document.createElement('tr');
719-
footerRow.setAttribute('part', 'row');
722+
footerRow.setAttribute('part', 'row footer-row');
720723
footerRow.setAttribute('role', 'row');
721724
footerRow.setAttribute('tabindex', '-1');
722725
this.$.footer.appendChild(footerRow);
@@ -726,25 +729,19 @@ export const GridMixin = (superClass) =>
726729
this.$.footer.removeChild(this.$.footer.firstElementChild);
727730
}
728731

729-
iterateChildren(this.$.header, (headerRow, index, rows) => {
732+
iterateChildren(this.$.header, (headerRow, index) => {
730733
this.__initRow(headerRow, columnTree[index], 'header', index === columnTree.length - 1);
731-
732-
const cells = getBodyRowCells(headerRow);
733-
updateCellsPart(cells, 'first-header-row-cell', index === 0);
734-
updateCellsPart(cells, 'last-header-row-cell', index === rows.length - 1);
735734
});
736735

737-
iterateChildren(this.$.footer, (footerRow, index, rows) => {
736+
iterateChildren(this.$.footer, (footerRow, index) => {
738737
this.__initRow(footerRow, columnTree[columnTree.length - 1 - index], 'footer', index === 0);
739-
740-
const cells = getBodyRowCells(footerRow);
741-
updateCellsPart(cells, 'first-footer-row-cell', index === 0);
742-
updateCellsPart(cells, 'last-footer-row-cell', index === rows.length - 1);
743738
});
744739

745740
// Sizer rows
746741
this.__initRow(this.$.sizer, columnTree[columnTree.length - 1]);
747742

743+
this.__updateHeaderFooterRowParts('header');
744+
this.__updateHeaderFooterRowParts('footer');
748745
this._resizeHandler();
749746
this._frozenCellsChanged();
750747
this._updateFirstAndLastColumn();
@@ -756,6 +753,20 @@ export const GridMixin = (superClass) =>
756753
this.__updateHeaderAndFooter();
757754
}
758755

756+
/** @private */
757+
__updateHeaderFooterRowParts(section) {
758+
const visibleRows = [...this.$[section].querySelectorAll('tr:not([hidden])')];
759+
[...this.$[section].children].forEach((row) => {
760+
updatePart(row, row === visibleRows.at(0), `first-${section}-row`);
761+
updatePart(row, row === visibleRows.at(-1), `last-${section}-row`);
762+
763+
getBodyRowCells(row).forEach((cell) => {
764+
updatePart(cell, row === visibleRows.at(0), `first-${section}-row-cell`);
765+
updatePart(cell, row === visibleRows.at(-1), `last-${section}-row-cell`);
766+
});
767+
});
768+
}
769+
759770
/**
760771
* @param {!HTMLElement} row
761772
* @param {boolean} loading

packages/grid/src/vaadin-grid.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ export type GridDefaultItem = any;
157157
* ---------------------------|----------------
158158
* `row` | Row in the internal table
159159
* `body-row` | Body row in the internal table
160+
* `header-row` | Header row in the internal table
161+
* `footer-row` | Footer row in the internal table
160162
* `collapsed-row` | Collapsed row
161163
* `expanded-row` | Expanded row
162164
* `selected-row` | Selected row
@@ -165,7 +167,11 @@ export type GridDefaultItem = any;
165167
* `odd-row` | Odd row
166168
* `even-row` | Even row
167169
* `first-row` | The first body row
170+
* `first-header-row` | The first header row
171+
* `first-footer-row` | The first footer row
168172
* `last-row` | The last body row
173+
* `last-header-row` | The last header row
174+
* `last-footer-row` | The last footer row
169175
* `dragstart-row` | Set on the row for one frame when drag is starting.
170176
* `dragover-above-row` | Set on the row when the a row is dragged over above
171177
* `dragover-below-row` | Set on the row when the a row is dragged over below

packages/grid/src/vaadin-grid.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ import { GridMixin } from './vaadin-grid-mixin.js';
158158
* ---------------------------|----------------
159159
* `row` | Row in the internal table
160160
* `body-row` | Body row in the internal table
161+
* `header-row` | Header row in the internal table
162+
* `footer-row` | Footer row in the internal table
161163
* `collapsed-row` | Collapsed row
162164
* `expanded-row` | Expanded row
163165
* `selected-row` | Selected row
@@ -166,7 +168,11 @@ import { GridMixin } from './vaadin-grid-mixin.js';
166168
* `odd-row` | Odd row
167169
* `even-row` | Even row
168170
* `first-row` | The first body row
171+
* `first-header-row` | The first header row
172+
* `first-footer-row` | The first footer row
169173
* `last-row` | The last body row
174+
* `last-header-row` | The last header row
175+
* `last-footer-row` | The last footer row
170176
* `dragstart-row` | Set on the row for one frame when drag is starting.
171177
* `dragover-above-row` | Set on the row when the a row is dragged over above
172178
* `dragover-below-row` | Set on the row when the a row is dragged over below

0 commit comments

Comments
 (0)