Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VirtualScroller: scrollInView method does not scroll to right item, when item is dynamically added #6986

Open
adam-koller opened this issue Dec 22, 2024 · 2 comments
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback

Comments

@adam-koller
Copy link

adam-koller commented Dec 22, 2024

Describe the bug

VirtualScroller: scrollInView method does not scroll to right item, when item is dynamically added
Same issue applies to DataTable when using VirtualScroller feature.

Reproducer

https://stackblitz.com/edit/qe6t4tk3?file=src%2FApp.vue

PrimeVue version

4.2.5

Vue version

3.4.29

Language

TypeScript

Build / Runtime

Vite

Browser(s)

Chrome

Steps to reproduce the behavior

Place a VirtualScroller component on the page.
Add an item to the items array.
Use the ScrollInView method, to scroll to the newly created item on the very bottom.
Observe, that it is not fully scrolling to the bottom.

Expected behavior

ScrollInView method shall display the newly created item on the very bottom of the VirtualScroller.

@adam-koller adam-koller added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 22, 2024
@tugcekucukoglu tugcekucukoglu added Resolution: Help Wanted Issue or pull request requires extra help and feedback and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Dec 26, 2024
Copy link

Due to PrimeVue team's busy roadmap, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. ✨ Thank you for your contribution! ✨

@adam-koller
Copy link
Author

adam-koller commented Dec 28, 2024

After some code analysis, I believe this is due to a change in Vue's watch functionality.
See: https://v3-migration.vuejs.org/breaking-changes/watch#_3-x-syntax
Also see: https://stackoverflow.com/questions/62729380/vue-watch-outputs-same-oldvalue-and-newvalue

If items are added to the items array of the VirtualScroller component, the watcher is not executed and component parameters are therewith not re-computed based on the updated number of items.

A potential fix to the items watcher could look as follows (without respecting, if the array changed at all).

        items: {
            handler(newValue) {
                this.init();
                this.calculateAutoSize();
            },
            deep: true
        },

Hope this helps and can be fixed in an upcoming release. Thank you.

adam-koller added a commit to adam-koller/primevue that referenced this issue Dec 29, 2024
adam-koller added a commit to adam-koller/primevue that referenced this issue Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Help Wanted Issue or pull request requires extra help and feedback
Projects
None yet
Development

No branches or pull requests

2 participants