@vaadin/component-base 24.3.8 → 24.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/component-base",
3
- "version": "24.3.8",
3
+ "version": "24.3.10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,5 +42,5 @@
42
42
  "@vaadin/testing-helpers": "^0.6.0",
43
43
  "sinon": "^13.0.2"
44
44
  },
45
- "gitHead": "144e479d60d7d52edd4d35aba032c6863c02e878"
45
+ "gitHead": "32a4f327e78490074eaefa768f58857b83ca6278"
46
46
  }
package/src/define.js CHANGED
@@ -9,7 +9,7 @@ export function defineCustomElement(CustomElement) {
9
9
  if (!defined) {
10
10
  Object.defineProperty(CustomElement, 'version', {
11
11
  get() {
12
- return '24.3.8';
12
+ return '24.3.10';
13
13
  },
14
14
  });
15
15
 
@@ -297,24 +297,41 @@ export class IronListAdapter {
297
297
  this._debouncers._increasePoolIfNeeded.cancel();
298
298
  }
299
299
 
300
+ // Prevent element update while the scroll position is being restored
301
+ this.__preventElementUpdates = true;
302
+
303
+ // Record the scroll position before changing the size
304
+ let fvi; // First visible index
305
+ let fviOffsetBefore; // Scroll offset of the first visible index
306
+ if (size > 0) {
307
+ fvi = this.adjustedFirstVisibleIndex;
308
+ fviOffsetBefore = this.__getIndexScrollOffset(fvi);
309
+ }
310
+
300
311
  // Change the size
301
312
  this.__size = size;
302
313
 
303
- if (!this._physicalItems) {
304
- // Not initialized yet
305
- this._itemsChanged({
306
- path: 'items',
307
- });
308
- this.__preventElementUpdates = true;
309
- flush();
310
- this.__preventElementUpdates = false;
311
- } else {
312
- // Already initialized, just update _virtualCount
313
- this._updateScrollerSize();
314
- this._virtualCount = this.items.length;
315
- this._render();
314
+ this._itemsChanged({
315
+ path: 'items',
316
+ });
317
+ flush();
318
+
319
+ // Try to restore the scroll position if the new size is larger than 0
320
+ if (size > 0) {
321
+ fvi = Math.min(fvi, size - 1);
322
+ // Note, calling scrollToIndex also updates the virtual index offset,
323
+ // causing the virtualizer to add more items when size is increased,
324
+ // and remove exceeding items when size is decreased.
325
+ this.scrollToIndex(fvi);
326
+
327
+ const fviOffsetAfter = this.__getIndexScrollOffset(fvi);
328
+ if (fviOffsetBefore !== undefined && fviOffsetAfter !== undefined) {
329
+ this._scrollTop += fviOffsetBefore - fviOffsetAfter;
330
+ }
316
331
  }
317
332
 
333
+ this.__preventElementUpdates = false;
334
+
318
335
  // When reducing size while invisible, iron-list does not update items, so
319
336
  // their hidden state is not updated and their __lastUpdatedIndex is not
320
337
  // reset. In that case force an update here.
@@ -326,8 +343,7 @@ export class IronListAdapter {
326
343
  requestAnimationFrame(() => this._resizeHandler());
327
344
  }
328
345
 
329
- // Schedule and flush a resize handler. This will cause a
330
- // re-render for the elements.
346
+ // Schedule and flush a resize handler
331
347
  this._resizeHandler();
332
348
  flush();
333
349
  }