Avoid excessive re-render of room list and member list (#31131)
* fix(list view): avoid re-create `onFocus` function at each render of the child items * fix(room list): update `onFocus` signature * fix(member list): update `onFocus` signature * fix(room list): avoid re-render at the beginning and end of the scroll * test(room list): remove scrolling test and props * test(member list): update member tile view tests * test(room list): update `ListView` focus test * test(member list): add `onFocus` test for member list tile
This commit is contained in:
@@ -363,7 +363,12 @@ describe("ListView", () => {
|
||||
const mockOnClick = jest.fn();
|
||||
|
||||
mockGetItemComponent.mockImplementation(
|
||||
(index: number, item: TestItemWithSeparator, context: any, onFocus: (e: React.FocusEvent) => void) => {
|
||||
(
|
||||
index: number,
|
||||
item: TestItemWithSeparator,
|
||||
context: any,
|
||||
onFocus: (item: TestItemWithSeparator, e: React.FocusEvent) => void,
|
||||
) => {
|
||||
const itemKey = typeof item === "string" ? item : item.id;
|
||||
const isFocused = context.tabIndexKey === itemKey;
|
||||
return (
|
||||
@@ -372,7 +377,7 @@ describe("ListView", () => {
|
||||
data-testid={`row-${index}`}
|
||||
tabIndex={isFocused ? 0 : -1}
|
||||
onClick={() => mockOnClick(item)}
|
||||
onFocus={onFocus}
|
||||
onFocus={(e) => onFocus(item, e)}
|
||||
>
|
||||
{item === SEPARATOR_ITEM ? "---" : (item as TestItem).name}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user