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

Add align: center option to scrollToIndex #213

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add align: center option to scrollToIndex
  • Loading branch information
inokawa committed Oct 18, 2023
commit 9bb5ea9de3bc46ac061233bb4be538967cf5079d
4 changes: 4 additions & 0 deletions src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export const createScroller = (
store._getItemOffset(index) +
store._getItemSize(index) -
store._getViewportSize()
: align === "center"
? () =>
store._getItemOffset(index) +
(store._getItemSize(index) - store._getViewportSize()) / 2
: () => store._getItemOffset(index)
);
},
Expand Down
3 changes: 2 additions & 1 deletion src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface CacheSnapshot {
* Alignment of item when calling scrollToIndex method.
*
* - `start`(default): Align the item to the start of the list.
* - `center`: Align the item to the center of the list.
* - `end`: Align the item to the end of the list.
*/
export type ScrollToIndexAlign = "start" | "end";
export type ScrollToIndexAlign = "start" | "center" | "end";
11 changes: 11 additions & 0 deletions stories/basics/VList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ export const ScrollTo: StoryObj = {
/>
start
</label>
<label style={{ marginLeft: 4 }}>
<input
type="radio"
style={{ marginLeft: 4 }}
checked={scrollIndexAlign === "center"}
onChange={() => {
setScrollToIndexAlign("center");
}}
/>
center
</label>
<label style={{ marginLeft: 4 }}>
<input
type="radio"
Expand Down
Loading