diff --git a/packages/frontend/src/components/chat/ChatList.tsx b/packages/frontend/src/components/chat/ChatList.tsx index 62946acab5..3e6ed4bf74 100644 --- a/packages/frontend/src/components/chat/ChatList.tsx +++ b/packages/frontend/src/components/chat/ChatList.tsx @@ -44,6 +44,7 @@ import type { MessageChatListItemData, } from './ChatListItemRow' import { isInviteLink } from '../../../../shared/util' +import { RovingTabindexProvider } from '../../contexts/RovingTabindex' const enum LoadStatus { FETCHING = 1, @@ -163,6 +164,8 @@ export default function ChatList(props: { const createChatByContactId = useCreateChatByContactId() const { selectChat } = useChat() + const tabindexWrapperElement = useRef(null) + const addContactOnClick = async () => { if (!queryStrIsValidEmail || !queryStr) return @@ -344,27 +347,31 @@ export default function ChatList(props: {
{({ width, height }) => ( -
+
{tx('search_in', searchChatInfo.name)} {messageResultIds.length !== 0 && ': ' + translate_n('n_messages', messageResultIds.length)}
- 'key' + messageResultIds[index]} - itemData={messagelistData} - itemHeight={CHATLISTITEM_MESSAGE_HEIGHT} + - {ChatListItemRowMessage} - + 'key' + messageResultIds[index]} + itemData={messagelistData} + itemHeight={CHATLISTITEM_MESSAGE_HEIGHT} + > + {ChatListItemRowMessage} + +
)} @@ -378,90 +385,97 @@ export default function ChatList(props: {
{({ width, height }) => ( -
+
{isSearchActive && (
{translate_n('n_chats', chatListIds.length)}
)} - | null) => - ((listRefRef.current as any) = ref) - } - itemKey={index => 'key' + chatListIds[index]} - itemData={chatlistData} - itemHeight={CHATLISTITEM_CHAT_HEIGHT} + {/* TODO RovingTabindex doesn't work well with virtualized + lists, because the currently active element might get removed + from DOM if scrolled out of view. */} + - {ChatListItemRowChat} - - {isSearchActive && ( - <> -
- {translate_n('n_contacts', contactIds.length)} -
- 'key' + contactIds[index]} - itemData={contactlistData} - itemHeight={CHATLISTITEM_CONTACT_HEIGHT} - > - {ChatListItemRowContact} - - {contactIds.length === 0 && - chatListIds.length === 0 && - queryStrIsValidEmail && ( + | null) => + ((listRefRef.current as any) = ref) + } + itemKey={index => 'key' + chatListIds[index]} + itemData={chatlistData} + itemHeight={CHATLISTITEM_CHAT_HEIGHT} + > + {ChatListItemRowChat} + + {isSearchActive && ( + <> +
+ {translate_n('n_contacts', contactIds.length)} +
+ 'key' + contactIds[index]} + itemData={contactlistData} + itemHeight={CHATLISTITEM_CONTACT_HEIGHT} + > + {ChatListItemRowContact} + + {contactIds.length === 0 && + chatListIds.length === 0 && + queryStrIsValidEmail && ( +
+ +
+ )} + {showPseudoListItemAddContactFromInviteLink && (
-
)} - {showPseudoListItemAddContactFromInviteLink && ( -
- +
+ {translated_messages_label(messageResultIds.length)}
- )} -
- {translated_messages_label(messageResultIds.length)} -
- 'key' + messageResultIds[index]} - itemData={messagelistData} - itemHeight={CHATLISTITEM_MESSAGE_HEIGHT} - > - {ChatListItemRowMessage} - - - )} + 'key' + messageResultIds[index]} + itemData={messagelistData} + itemHeight={CHATLISTITEM_MESSAGE_HEIGHT} + > + {ChatListItemRowMessage} + + + )} +
(null) + + const { + tabIndex, + onKeydown: tabindexOnKeydown, + setAsActiveElement: tabindexSetAsActiveElement, + } = useRovingTabindex(ref) + return (