mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-06 20:10:12 +02:00
add scrollToIndex alignment to lists
This commit is contained in:
@@ -360,10 +360,24 @@ export const ItemGridList = ({
|
||||
const controls = useDefaultItemListControls();
|
||||
|
||||
const scrollToIndex = useCallback(
|
||||
(index: number) => {
|
||||
(
|
||||
index: number,
|
||||
options?: { align?: 'bottom' | 'center' | 'top'; behavior?: 'auto' | 'smooth' },
|
||||
) => {
|
||||
if (!listRef.current || !tableMeta) return;
|
||||
const row = Math.floor(index / tableMeta.columnCount);
|
||||
listRef.current.scrollToItem(row, 'smart');
|
||||
|
||||
// Map alignment options to react-window's alignment
|
||||
let alignment: 'auto' | 'center' | 'end' | 'smart' | 'start' = 'smart';
|
||||
if (options?.align === 'top') {
|
||||
alignment = 'start';
|
||||
} else if (options?.align === 'center') {
|
||||
alignment = 'center';
|
||||
} else if (options?.align === 'bottom') {
|
||||
alignment = 'end';
|
||||
}
|
||||
|
||||
listRef.current.scrollToItem(row, alignment);
|
||||
},
|
||||
[tableMeta],
|
||||
);
|
||||
@@ -580,8 +594,8 @@ export const ItemGridList = ({
|
||||
const imperativeHandle: ItemListHandle = useMemo(() => {
|
||||
return {
|
||||
internalState,
|
||||
scrollToIndex: (index: number) => {
|
||||
scrollToIndex(index);
|
||||
scrollToIndex: (index: number, options?: { align?: 'bottom' | 'center' | 'top' }) => {
|
||||
scrollToIndex(index, options);
|
||||
},
|
||||
scrollToOffset: (offset: number) => {
|
||||
scrollToOffset(offset);
|
||||
|
||||
Reference in New Issue
Block a user