Skip to content

Commit

Permalink
fix: don't update items manually on selection change (CP) (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Jan 26, 2022
1 parent 4d1fb6e commit 8d34755
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/vaadin-grid-column.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,9 @@
_setFooterTemplateOrRenderer(footerTemplate, footerRenderer, footerCell) {
if ((footerTemplate || footerRenderer) && footerCell) {
this.__setColumnTemplateOrRenderer(footerTemplate, footerRenderer, [footerCell]);
this._grid.__updateHeaderFooterRowVisibility(footerCell.parentElement);
if (this._grid) {
this._grid.__updateHeaderFooterRowVisibility(footerCell.parentElement);
}
}
}

Expand Down Expand Up @@ -485,7 +487,7 @@
}
}

if (headerCell) {
if (headerCell && this._grid) {
this._grid.__updateHeaderFooterRowVisibility(headerCell.parentElement);
}
}
Expand Down
6 changes: 1 addition & 5 deletions src/vaadin-grid-selection-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,7 @@

/** @private */
_selectedItemsChanged(e) {
if (this.$.items.children.length && (e.path === 'selectedItems' || e.path === 'selectedItems.splices')) {
Array.from(this.$.items.children).forEach(row => {
this._updateItem(row, row._item);
});
}
this._assignModels();
}

/** @private */
Expand Down
8 changes: 8 additions & 0 deletions test/selecting.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
expect(rows[1].hasAttribute('selected')).to.be.false;
});

it('should not update selected attribute for hidden rows', () => {
grid.size = 0;
grid.selectedItems = [];
// Even though all selections were cleared, the first row is hidden / not in use
// because the grid's size was set to 0. Unused rows should never be updated.
expect(rows[0].hasAttribute('selected')).to.be.true;
});

it('should deselect an equaling item', () => {
grid.itemIdPath = 'value';
const cells = getRowCells(rows[0]);
Expand Down

0 comments on commit 8d34755

Please # to comment.