Skip to content

Conversation

@soren121
Copy link
Contributor

@soren121 soren121 commented Feb 24, 2025

Fixes #931

This fixes a regression caused by PR #864, which adjusted the center alignment of scrollToIndex to center on the item. That change moved the center alignment adjustment from getOffsetForAlignment into getOffsetForIndex. However, scrollToOffset also relied on the former function, and now it lacks an implementation for align: center.

This PR restores the center alignment to getOffsetForAlignment, but adds a new itemSize parameter. This lets us share the center alignment implementation with both scroll functions, while also taking the item size into account when calculating the center alignment for scrollToIndex.

@soren121 soren121 changed the title fix(virtual-core): Restore center alignment in getOffsetForAlignment, add item size awareness fix(virtual-core): fixes center alignment option for scrollToOffset Feb 25, 2025
Copy link
Collaborator

@piecyk piecyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good 👍 When checking the getOffsetForAlignment current we calculate the max offset via reading scrollWidth/scrollHeight, kinda feels we can use the totalSize so just

const maxOffset = this.getTotalSize() - size

and drop the scrollSize.

@nx-cloud
Copy link

nx-cloud bot commented Feb 25, 2025

View your CI Pipeline Execution ↗ for commit 088ca22.

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 2m 30s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 18s View ↗

☁️ Nx Cloud last updated this comment at 2025-02-25 07:05:51 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 25, 2025

Open in Stackblitz

More templates

@tanstack/angular-virtual

npm i https://pkg.pr.new/@tanstack/angular-virtual@935

@tanstack/lit-virtual

npm i https://pkg.pr.new/@tanstack/lit-virtual@935

@tanstack/solid-virtual

npm i https://pkg.pr.new/@tanstack/solid-virtual@935

@tanstack/react-virtual

npm i https://pkg.pr.new/@tanstack/react-virtual@935

@tanstack/svelte-virtual

npm i https://pkg.pr.new/@tanstack/svelte-virtual@935

@tanstack/virtual-core

npm i https://pkg.pr.new/@tanstack/virtual-core@935

@tanstack/vue-virtual

npm i https://pkg.pr.new/@tanstack/vue-virtual@935

commit: 088ca22

@piecyk piecyk merged commit ace7d93 into TanStack:main Feb 25, 2025
6 checks passed
@soren121
Copy link
Contributor Author

When checking the getOffsetForAlignment current we calculate the max offset via reading scrollWidth/scrollHeight, kinda feels we can use the totalSize

@piecyk Yeah, that seems like a reasonable improvement to me.

@soren121 soren121 deleted the issue-931 branch February 27, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scrollToOffset with align: 'center' doesn't align correctly anymore

2 participants