Skip to content

Commit

Permalink
fix: check if grid column is attached (#2160)
Browse files Browse the repository at this point in the history
cherry-pick: check if grid column is attached (vaadin/web-components#195)

Fixes: #1981
Warranty: Prevent an exception when changing the size after removing columns
  • Loading branch information
tulioag authored Apr 8, 2021
1 parent f2fedc1 commit 9f45ec4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/vaadin-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,9 @@ class GridElement extends ElementMixin(
}

if (this._columnTree) {
this._columnTree[this._columnTree.length - 1].forEach((c) => c.notifyPath && c.notifyPath('_cells.*', c._cells));
this._columnTree[this._columnTree.length - 1].forEach(
(c) => c.isConnected && c.notifyPath && c.notifyPath('_cells.*', c._cells)
);
}

beforeNextRender(this, () => {
Expand Down
9 changes: 9 additions & 0 deletions test/column.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,13 @@ describe('column', () => {
expect(column._bodyTemplate).to.eql(template2);
});
});

it('should not throw an exception when size is changed after removing column', () => {
expect(grid.size).to.equal(10);
expect(column.isConnected).to.be.true;
column.remove();
expect(column.isConnected).to.be.false;
expect(() => (grid.size = 11)).not.to.throw();
expect(grid.size).to.equal(11);
});
});

0 comments on commit 9f45ec4

Please sign in to comment.