Skip to content

Commit 20a64e3

Browse files
authored
fix: configure ResizeObserver to observe entire border box (#10378)
1 parent f409aa0 commit 20a64e3

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

packages/component-base/src/virtualizer-iron-list-adapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ export class IronListAdapter {
447447
physicalItems.forEach((el) => {
448448
el.style.position = 'absolute';
449449
fragment.appendChild(el);
450-
this.__resizeObserver.observe(el);
450+
this.__resizeObserver.observe(el, { box: 'border-box' });
451451
});
452452
this.elementsContainer.appendChild(fragment);
453453
return physicalItems;

packages/component-base/test/virtualizer-item-height.test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from '@vaadin/chai-plugins';
2-
import { aTimeout, fixtureSync, nextFrame } from '@vaadin/testing-helpers';
2+
import { aTimeout, fixtureSync, nextFrame, nextResize } from '@vaadin/testing-helpers';
33
import sinon from 'sinon';
44
import { Virtualizer } from '../src/virtualizer.js';
55

@@ -413,6 +413,43 @@ describe('virtualizer - item height - lazy rendering', () => {
413413
});
414414
});
415415

416+
describe('virtualizer - item padding', () => {
417+
let virtualizer;
418+
let scrollTarget;
419+
let item0, item1;
420+
421+
beforeEach(async () => {
422+
scrollTarget = fixtureSync(`
423+
<div style="height: 200px;">
424+
<div class="container"></div>
425+
</div>
426+
`);
427+
428+
virtualizer = new Virtualizer({
429+
createElements: (count) => Array.from({ length: count }, () => document.createElement('div')),
430+
updateElement: (el, index) => {
431+
el.style.paddingBottom = '20px';
432+
el.style.boxSizing = 'border-box';
433+
el.id = `item-${index}`;
434+
},
435+
scrollTarget,
436+
scrollContainer: scrollTarget.firstElementChild,
437+
});
438+
virtualizer.size = 2;
439+
await nextResize(scrollTarget);
440+
await nextFrame();
441+
});
442+
443+
it('should adjust item positions after an item padding box changes', async () => {
444+
item0 = document.querySelector('#item-0');
445+
item1 = document.querySelector('#item-1');
446+
item0.style.paddingBottom = '50px';
447+
await nextResize(scrollTarget);
448+
await nextFrame();
449+
expect(item1.getBoundingClientRect().top).to.equal(item0.getBoundingClientRect().bottom);
450+
});
451+
});
452+
416453
describe('virtualizer - item height - placeholders are disabled', () => {
417454
let virtualizer;
418455
let scrollTarget;

packages/grid/src/vaadin-grid-row-details-mixin.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ export const RowDetailsMixin = (superClass) =>
6868
entries.forEach(({ target: cell }) => {
6969
this._updateDetailsCellHeight(cell.parentElement);
7070
});
71-
72-
// This workaround is needed until Safari also supports
73-
// ResizeObserver.observe with {box: 'border-box'}
74-
this.__virtualizer.__adapter._resizeHandler();
7571
});
7672
}
7773

0 commit comments

Comments
 (0)