Skip to content

Commit

Permalink
fix: don't update items manually on selection change (#3347)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Jan 25, 2022
1 parent dc6d693 commit 6956971
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions packages/grid/src/vaadin-grid-column.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ export const ColumnBaseMixin = (superClass) =>
}

this.__renderCellsContent(headerRenderer, [headerCell]);
this._grid.__updateHeaderFooterRowVisibility(headerCell.parentElement);
if (this._grid) {
this._grid.__updateHeaderFooterRowVisibility(headerCell.parentElement);
}
}

/** @protected */
Expand Down Expand Up @@ -536,7 +538,9 @@ export const ColumnBaseMixin = (superClass) =>
}

this.__renderCellsContent(footerRenderer, [footerCell]);
this._grid.__updateHeaderFooterRowVisibility(footerCell.parentElement);
if (this._grid) {
this._grid.__updateHeaderFooterRowVisibility(footerCell.parentElement);
}
}

/** @protected */
Expand Down
8 changes: 2 additions & 6 deletions packages/grid/src/vaadin-grid-selection-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,8 @@ export const SelectionMixin = (superClass) =>
}

/** @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);
});
}
_selectedItemsChanged() {
this.requestContentUpdate();
}

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/grid/test/selection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ describe('selection', () => {
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';
grid.selectedItems = [rows[0]._item];
Expand Down

0 comments on commit 6956971

Please sign in to comment.