Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: GroupedList.scrollToIndex() now targets group index",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
22 changes: 21 additions & 1 deletion packages/react/src/components/GroupedList/GroupedList.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ export class GroupedListBase extends React.Component<IGroupedListProps, IGrouped
}

public scrollToIndex(index: number, measureItem?: (itemIndex: number) => number, scrollToMode?: ScrollToMode): void {
const groupIndex = this._getGroupIndexFromItemIndex(index);
const scrollIndex = groupIndex > -1 ? groupIndex : index;
if (this._list.current) {
this._list.current.scrollToIndex(index, measureItem, scrollToMode);
this._list.current.scrollToIndex(scrollIndex, measureItem, scrollToMode);
}
}

Expand Down Expand Up @@ -404,4 +406,22 @@ export class GroupedListBase extends React.Component<IGroupedListProps, IGrouped
this._isSomeGroupExpanded = newIsSomeGroupExpanded;
}
}

private _getGroupIndexFromItemIndex(itemIndex: number): number {
const { groups } = this.state;

if (!groups) {
return -1;
}

for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
const group = groups[groupIndex];

if (itemIndex >= group.startIndex && itemIndex < group.startIndex + group.count) {
return groupIndex;
}
}

return -1;
}
}