Skip to content

Commit

Permalink
fix: run the class name generator only for loaded rows (#3789) (#3796)
Browse files Browse the repository at this point in the history
Co-authored-by: Sergey Vinogradov <mr.vursen@gmail.com>
  • Loading branch information
vaadin-bot and vursen authored May 6, 2022
1 parent 4e5893d commit 6f402bb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/grid/src/vaadin-grid-styling-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const StylingMixin = (superClass) =>
*/
generateCellClassNames() {
Array.from(this.$.items.children)
.filter((row) => !row.hidden)
.filter((row) => !row.hidden && !row.hasAttribute('loading'))
.forEach((row) => this._generateCellClassNames(row, this.__getRowModel(row)));
}

Expand Down
31 changes: 31 additions & 0 deletions packages/grid/test/class-name-generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,35 @@ describe('class name generator', () => {
assertClassList(getContainerCell(grid.$.items, 1, 0), ['odd']);
assertClassList(getContainerCell(grid.$.items, 1, 1), ['odd']);
});

describe('async data provider', () => {
let clock;

beforeEach(() => {
clock = sinon.useFakeTimers({
shouldClearNativeTimers: true
});

grid.dataProvider = (params, callback) => {
setTimeout(() => infiniteDataProvider(params, callback), 10);
};
});

afterEach(() => {
clock.restore();
});

it('should only run the generator for the rows that are loaded', async () => {
const spy = sinon.spy();
grid.cellClassNameGenerator = spy;
spy.resetHistory();

grid.generateCellClassNames();
expect(spy.called).to.be.false;

clock.tick(10);
grid.generateCellClassNames();
expect(spy.called).to.be.true;
});
});
});

0 comments on commit 6f402bb

Please sign in to comment.