Skip to content

[virtualizer] Unexpected position after scrolling to an index and decreasing size to that index #7079

Closed

Description

@vursen

Description

Finding from vaadin/flow-components#5883

Let's say I have a virtual list with 600 items. I scroll to the item 500 and it causes the number of items to decrease to 500. I'd expect the virtualizer to set the scroll position to the end because the item 500 has become the last one. However, I observe different behavior:

Screen.Recording.2024-01-12.at.15.49.10.mov

Expected outcome

The scroll position should be at the end.

Minimal reproducible example

<script type="module" src="./common.js"></script>
<script type="module">
  import { Virtualizer } from '@vaadin/component-base/src/virtualizer.js';

  const scrollTarget = document.querySelector('#scroll-target');
  const scrollContainer = document.querySelector('#scroll-container');

  const virtualizer = new Virtualizer({
    createElements: (count) => [...Array(count)].map(() => document.createElement('div')),
    updateElement: (el, index) => {
      el.style.width = '100%';
      el.style.display = 'flex';
      el.style.alignItems = 'center';
      el.style.background = index % 2 === 0 ? '#DCDCDC' : '#C0C0C0';
      el.style.height = '35px';
      el.style.padding = '0 10px';
      el.textContent = `Item ${index}`;
    },
    scrollTarget,
    scrollContainer,
    reorderElements: true,
  });

  virtualizer.size = 200;

  const button = document.querySelector('button');
  button.addEventListener('click', () => {
    virtualizer.scrollToIndex(150);

    requestAnimationFrame(() => {
      virtualizer.size = 100;
    });
  });
</script>

<button>Scroll and change size</button>

<div style="height: 400px;" id="scroll-target">
  <div id="scroll-container"></div>
</div>

Steps to reproduce

  1. Add the snippet to a page
  2. Click the button "Scroll and change size"

Environment

Vaadin version(s): 24.4 and earlier
OS: Mac OS

Browsers

No response

Activity

  1. vursen commented on Mar 11, 2024

    @vursen
    ContributorAuthor

    This is a regression introduced by #5650.

  2. self-assigned this
    on Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions