diff --git a/packages/grid/src/vaadin-grid-column-reordering-mixin.js b/packages/grid/src/vaadin-grid-column-reordering-mixin.js index 43d7082762d..cea4c1772b7 100644 --- a/packages/grid/src/vaadin-grid-column-reordering-mixin.js +++ b/packages/grid/src/vaadin-grid-column-reordering-mixin.js @@ -457,9 +457,12 @@ export const ColumnReorderingMixin = (superClass) => } }); + [...this.$.items.children, this.$.sizer].forEach((row) => { + this._updateFirstAndLastColumnForRow(row); + }); + this.__scheduleRenderHeaderFooter(); this._debounceUpdateFrozenColumn(); - this._updateFirstAndLastColumn(); } /** diff --git a/packages/grid/src/vaadin-grid-dynamic-columns-mixin.js b/packages/grid/src/vaadin-grid-dynamic-columns-mixin.js index 1e10ac91bdf..6068047a4e5 100644 --- a/packages/grid/src/vaadin-grid-dynamic-columns-mixin.js +++ b/packages/grid/src/vaadin-grid-dynamic-columns-mixin.js @@ -143,14 +143,6 @@ export const DynamicColumnsMixin = (superClass) => }); } - /** @protected */ - _updateFirstAndLastColumn() { - // The sizer is a element, so it isn't matched by the selector - [...this.shadowRoot.querySelectorAll('tr'), this.$.sizer].forEach((row) => { - this._updateFirstAndLastColumnForRow(row); - }); - } - /** * @param {!HTMLElement} row * @protected diff --git a/packages/grid/src/vaadin-grid-header-footer-rendering-mixin.js b/packages/grid/src/vaadin-grid-header-footer-rendering-mixin.js index 6cdc79f45b1..900d54c0b30 100644 --- a/packages/grid/src/vaadin-grid-header-footer-rendering-mixin.js +++ b/packages/grid/src/vaadin-grid-header-footer-rendering-mixin.js @@ -5,10 +5,12 @@ */ import { html, nothing, render } from 'lit'; import { cache } from 'lit/directives/cache.js'; +import { classMap } from 'lit/directives/class-map.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { repeat } from 'lit/directives/repeat.js'; import { microTask } from '@vaadin/component-base/src/async.js'; import { Debouncer } from '@vaadin/component-base/src/debounce.js'; +import { partMap } from '@vaadin/component-base/src/directives/part-map.js'; import { cellContent } from './directives/cell-content-directive.js'; function isEmptyCell(column, level, columnTree) { @@ -78,10 +80,10 @@ export const HeaderFooterRenderingMixin = (superClass) => } #renderHeader(columnTree) { - render(columnTree.map(this.#renderHeaderRow), this.$.header, { host: this }); + const rows = this.#getRows(columnTree, 'header'); + render(rows.map(this.#renderHeaderRow), this.$.header, { host: this }); this.$.table.toggleAttribute('has-header', !!this.$.header.querySelector('tr:not([hidden])')); - this.__updateHeaderFooterRowParts('header'); this.$.header.querySelectorAll('.header-cell').forEach((cell) => { const column = cell._column; @@ -94,19 +96,24 @@ export const HeaderFooterRenderingMixin = (superClass) => }); } - #renderHeaderRow = (columns, level, columnTree) => { + #renderHeaderRow = ({ level, cells, isLastRow, isFirstRow, isRowVisible }) => { + const rowParts = { + 'first-header-row': isFirstRow, + 'last-header-row': isLastRow, + }; + return html` ${repeat( - columns, - (column) => column._id, - (column) => { + cells, + ({ column }) => column._id, + ({ column, isFirstCell, isLastCell }) => { // `cache` keeps the cell and its rendered content when the // column gets hidden, so it can be restored as-is when the // column is shown again. @@ -114,11 +121,20 @@ export const HeaderFooterRenderingMixin = (superClass) => return cache(nothing); } + const cellParts = { + 'first-header-row-cell': isFirstRow, + 'last-header-row-cell': isLastRow, + 'first-column-cell': isFirstCell, + 'last-column-cell': isLastCell, + }; + return cache(html` }; #renderFooter(columnTree) { - render(columnTree.map(this.#renderFooterRow).toReversed(), this.$.footer, { host: this }); + const rows = this.#getRows(columnTree, 'footer'); + render(rows.map(this.#renderFooterRow), this.$.footer, { host: this }); this.$.table.toggleAttribute('has-footer', !!this.$.footer.querySelector('tr:not([hidden])')); - this.__updateHeaderFooterRowParts('footer'); this.$.footer.querySelectorAll('.footer-cell').forEach((cell) => { const column = cell._column; @@ -155,19 +171,24 @@ export const HeaderFooterRenderingMixin = (superClass) => }); } - #renderFooterRow = (columns, level, columnTree) => { + #renderFooterRow = ({ level, cells, isLastRow, isFirstRow, isRowVisible }) => { + const rowParts = { + 'first-footer-row': isFirstRow, + 'last-footer-row': isLastRow, + }; + return html` ${repeat( - columns, - (column) => column._id, - (column) => { + cells, + ({ column }) => column._id, + ({ column, isFirstCell, isLastCell }) => { // `cache` keeps the cell and its rendered content when the // column gets hidden, so it can be restored as-is when the // column is shown again. @@ -175,11 +196,20 @@ export const HeaderFooterRenderingMixin = (superClass) => return cache(nothing); } + const cellParts = { + 'first-footer-row-cell': isFirstRow, + 'last-footer-row-cell': isLastRow, + 'first-column-cell': isFirstCell, + 'last-column-cell': isLastCell, + }; + return cache(html` `; }; + + #getRows(columnTree, section) { + let rows = columnTree.map((columns, level) => { + const visibleColumns = columns.filter((column) => !column.hidden); + + return { + level, + cells: columns.map((column) => { + return { + column, + isFirstCell: column === visibleColumns.at(0), + isLastCell: column === visibleColumns.at(-1), + }; + }), + isRowVisible: + section === 'header' + ? isHeaderRowVisible(columns, level, columnTree) + : isFooterRowVisible(columns, level, columnTree), + }; + }); + + if (section === 'footer') { + rows = rows.toReversed(); + } + + const visibleRows = rows.filter((row) => row.isRowVisible); + + return rows.map((row) => { + return { + ...row, + isFirstRow: row === visibleRows.at(0), + isLastRow: row === visibleRows.at(-1), + }; + }); + } }; diff --git a/packages/grid/src/vaadin-grid-mixin.js b/packages/grid/src/vaadin-grid-mixin.js index 7d27fd0dffc..3d22ac80cb3 100644 --- a/packages/grid/src/vaadin-grid-mixin.js +++ b/packages/grid/src/vaadin-grid-mixin.js @@ -597,7 +597,6 @@ export const GridMixin = (superClass) => this._resizeHandler(); this._frozenCellsChanged(); - this._updateFirstAndLastColumn(); this._resetKeyboardNavigation(); this.__a11yUpdateHeaderRows(); this.__a11yUpdateFooterRows(); @@ -605,22 +604,6 @@ export const GridMixin = (superClass) => this.__updateHeaderAndFooter(); } - /** @private */ - __updateHeaderFooterRowParts(section) { - const visibleRows = [...this.$[section].querySelectorAll('tr:not([hidden])')]; - [...this.$[section].children].forEach((row) => { - updatePart(row, `first-${section}-row`, row === visibleRows.at(0)); - updatePart(row, `last-${section}-row`, row === visibleRows.at(-1)); - - getBodyRowCells(row).forEach((cell) => { - updatePart(cell, `first-${section}-row-cell`, row === visibleRows.at(0)); - updatePart(cell, `last-${section}-row-cell`, row === visibleRows.at(-1)); - }); - - this._updateFirstAndLastColumnForRow(row); - }); - } - /** * @param {!HTMLElement} row * @param {boolean} loading diff --git a/packages/grid/test/dom/__snapshots__/grid.test.snap.js b/packages/grid/test/dom/__snapshots__/grid.test.snap.js index 31d29da748d..b2e7252eec5 100644 --- a/packages/grid/test/dom/__snapshots__/grid.test.snap.js +++ b/packages/grid/test/dom/__snapshots__/grid.test.snap.js @@ -92,7 +92,7 @@ snapshots["vaadin-grid basic shadow default"] = @@ -332,7 +332,7 @@ snapshots["vaadin-grid basic shadow selected"] = @@ -573,7 +573,7 @@ snapshots["vaadin-grid basic shadow details opened"] = @@ -802,7 +802,7 @@ snapshots["vaadin-grid basic shadow hidden column"] = @@ -987,7 +987,7 @@ snapshots["vaadin-grid basic shadow hidden column selected"] = @@ -1185,7 +1185,7 @@ snapshots["vaadin-grid basic shadow with footer"] = @@ -1448,7 +1448,7 @@ snapshots["vaadin-grid column groups default"] = @@ -1826,7 +1826,7 @@ snapshots["vaadin-grid hidden column group with group header"] = aria-rowindex="1" class="header-row row" hidden="" - part="row header-row" + part="row header-row " role="row" tabindex="-1" > @@ -1834,7 +1834,7 @@ snapshots["vaadin-grid hidden column group with group header"] = class="cell first-column-cell header-cell last-column-cell" first-column="" last-column="" - part="cell header-cell first-column-cell last-column-cell" + part="cell header-cell first-column-cell last-column-cell " role="columnheader" style="width: 100px; flex-grow: 1;" tabindex="-1" @@ -1847,7 +1847,7 @@ snapshots["vaadin-grid hidden column group with group header"] = aria-rowindex="2" class="header-row row" hidden="" - part="row header-row" + part="row header-row " role="row" tabindex="-1" > @@ -1952,7 +1952,7 @@ snapshots["vaadin-grid hidden column group with group header"] = aria-rowindex="3" class="footer-row row" hidden="" - part="row footer-row" + part="row footer-row " role="row" tabindex="-1" > @@ -1973,7 +1973,7 @@ snapshots["vaadin-grid hidden column group with group header"] = aria-rowindex="4" class="footer-row row" hidden="" - part="row footer-row" + part="row footer-row " role="row" tabindex="-1" > @@ -1981,7 +1981,7 @@ snapshots["vaadin-grid hidden column group with group header"] = class="cell first-column-cell footer-cell last-column-cell" first-column="" last-column="" - part="cell footer-cell first-column-cell last-column-cell" + part="cell footer-cell first-column-cell last-column-cell " role="gridcell" style="width: 100px; flex-grow: 1;" tabindex="-1" @@ -2053,7 +2053,7 @@ snapshots["vaadin-grid hidden column group with group and column header"] = aria-rowindex="1" class="header-row row" hidden="" - part="row header-row" + part="row header-row " role="row" tabindex="-1" > @@ -2061,7 +2061,7 @@ snapshots["vaadin-grid hidden column group with group and column header"] = class="cell first-column-cell header-cell last-column-cell" first-column="" last-column="" - part="cell header-cell first-column-cell last-column-cell" + part="cell header-cell first-column-cell last-column-cell " role="columnheader" style="width: 100px; flex-grow: 1;" tabindex="-1" @@ -2179,7 +2179,7 @@ snapshots["vaadin-grid hidden column group with group and column header"] = aria-rowindex="5" class="footer-row row" hidden="" - part="row footer-row" + part="row footer-row " role="row" tabindex="-1" > @@ -2200,7 +2200,7 @@ snapshots["vaadin-grid hidden column group with group and column header"] = aria-rowindex="6" class="footer-row row" hidden="" - part="row footer-row" + part="row footer-row " role="row" tabindex="-1" > @@ -2208,7 +2208,7 @@ snapshots["vaadin-grid hidden column group with group and column header"] = class="cell first-column-cell footer-cell last-column-cell" first-column="" last-column="" - part="cell footer-cell first-column-cell last-column-cell" + part="cell footer-cell first-column-cell last-column-cell " role="gridcell" style="width: 100px; flex-grow: 1;" tabindex="-1" @@ -2279,7 +2279,7 @@ snapshots["vaadin-grid hidden column group with group footer"] = aria-rowindex="1" class="header-row row" hidden="" - part="row header-row" + part="row header-row " role="row" tabindex="-1" > @@ -2287,7 +2287,7 @@ snapshots["vaadin-grid hidden column group with group footer"] = class="cell first-column-cell header-cell last-column-cell" first-column="" last-column="" - part="cell header-cell first-column-cell last-column-cell" + part="cell header-cell first-column-cell last-column-cell " role="columnheader" style="width: 100px; flex-grow: 1;" tabindex="-1" @@ -2300,7 +2300,7 @@ snapshots["vaadin-grid hidden column group with group footer"] = aria-rowindex="2" class="header-row row" hidden="" - part="row header-row" + part="row header-row " role="row" tabindex="-1" > @@ -2405,7 +2405,7 @@ snapshots["vaadin-grid hidden column group with group footer"] = aria-rowindex="3" class="footer-row row" hidden="" - part="row footer-row" + part="row footer-row " role="row" tabindex="-1" > @@ -2426,7 +2426,7 @@ snapshots["vaadin-grid hidden column group with group footer"] = aria-rowindex="4" class="footer-row row" hidden="" - part="row footer-row" + part="row footer-row " role="row" tabindex="-1" > @@ -2434,7 +2434,7 @@ snapshots["vaadin-grid hidden column group with group footer"] = class="cell first-column-cell footer-cell last-column-cell" first-column="" last-column="" - part="cell footer-cell first-column-cell last-column-cell" + part="cell footer-cell first-column-cell last-column-cell " role="gridcell" style="width: 100px; flex-grow: 1;" tabindex="-1" @@ -2510,7 +2510,7 @@ snapshots["vaadin-grid column reordering reordered"] = @@ -2739,7 +2739,7 @@ snapshots["vaadin-grid column reordering reordered details opened"] =