mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-05 12:16:53 +02:00
Fix location of scrollToIndex and add useCallback
This commit is contained in:
parent
7571ea3dd2
commit
919b5ee452
@ -6,7 +6,7 @@ Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { Form } from "@vector-im/compound-web";
|
||||
import React, { useRef, type JSX } from "react";
|
||||
import React, { useCallback, useRef, type JSX } from "react";
|
||||
import { Virtuoso, VirtuosoHandle } from "react-virtuoso";
|
||||
|
||||
import { Flex } from "../../../utils/Flex";
|
||||
@ -43,17 +43,21 @@ const MemberListView: React.FC<IProps> = (props: IProps) => {
|
||||
}
|
||||
};
|
||||
|
||||
const keyDownCallback = React.useCallback(
|
||||
const scrollToIndex = useCallback(
|
||||
(index: number): void => {
|
||||
ref?.current?.scrollIntoView({
|
||||
index: index,
|
||||
behavior: "auto",
|
||||
done: () => {
|
||||
setFocusedIndex(index);
|
||||
},
|
||||
});
|
||||
},
|
||||
[ref],
|
||||
);
|
||||
|
||||
const keyDownCallback = useCallback(
|
||||
(e: any) => {
|
||||
const scrollToIndex = (index: number): void => {
|
||||
ref?.current?.scrollIntoView({
|
||||
index: index,
|
||||
behavior: "auto",
|
||||
done: () => {
|
||||
setFocusedIndex(index);
|
||||
},
|
||||
});
|
||||
};
|
||||
if (e.code === "ArrowUp") {
|
||||
const nextItemIsSeparator = focusedIndex > 1 && vm.members[focusedIndex - 1] === SEPARATOR;
|
||||
const nextMemberOffset = nextItemIsSeparator ? 2 : 1;
|
||||
@ -74,10 +78,10 @@ const MemberListView: React.FC<IProps> = (props: IProps) => {
|
||||
}
|
||||
}
|
||||
},
|
||||
[focusedIndex, ref, setFocusedIndex, vm, totalRows],
|
||||
[scrollToIndex, focusedIndex, setFocusedIndex, vm, totalRows],
|
||||
);
|
||||
|
||||
const scrollerRef = React.useCallback(
|
||||
const scrollerRef = useCallback(
|
||||
(element: any) => {
|
||||
if (element) {
|
||||
element.addEventListener("keydown", keyDownCallback);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user