Skip to content

Commit

Permalink
fix: render typing indicator outside the VirtualizedMessageList scrol…
Browse files Browse the repository at this point in the history
…l container
  • Loading branch information
MartinCupela committed May 29, 2024
1 parent 7919438 commit 4fce8e5
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/components/MessageList/VirtualizedMessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
calculateFirstItemIndex,
calculateItemIndex,
EmptyPlaceholder,
Footer,
Header,
Item,
makeItemsRenderedHandler,
Expand Down Expand Up @@ -232,6 +231,7 @@ const VirtualizedMessageListWithContext = <
UnreadMessagesNotification = DefaultUnreadMessagesNotification,
UnreadMessagesSeparator,
VirtualMessage: MessageUIComponentFromContext = MessageSimple,
TypingIndicator,
} = useComponentContext<StreamChatGenerics>('VirtualizedMessageList');
const MessageUIComponent = MessageUIComponentFromProps || MessageUIComponentFromContext;

Expand Down Expand Up @@ -435,7 +435,6 @@ const VirtualizedMessageListWithContext = <
className='str-chat__message-list-scroll'
components={{
EmptyPlaceholder,
Footer,
Header,
Item,
...virtuosoComponentsFromProps,
Expand Down Expand Up @@ -490,6 +489,7 @@ const VirtualizedMessageListWithContext = <
{...(defaultItemHeight ? { defaultItemHeight } : {})}
/>
</div>
{TypingIndicator && <TypingIndicator />}
</MessageListMainPanel>
<MessageListNotifications
hasNewMessages={newMessagesNotification}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ export const EmptyPlaceholder = <
</>
);
};
export const Footer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
>() => {
const { TypingIndicator } = useComponentContext<StreamChatGenerics>('VirtualizedMessageList');
return TypingIndicator ? <TypingIndicator /> : null;
};

export const messageRenderer = <
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import {
EmptyPlaceholder,
Footer,
Header,
Item,
messageRenderer,
Expand Down Expand Up @@ -206,25 +205,6 @@ describe('VirtualizedMessageComponents', () => {
});
});

describe('Footer', () => {
it('should render nothing in Footer by default', () => {
const { container } = renderElements(<Footer />);
expect(container).toMatchInlineSnapshot(`<div />`);
});
it('should render custom TypingIndicator in Footer', () => {
const TypingIndicator = () => <div>Custom TypingIndicator</div>;
const componentContext = { TypingIndicator };
const { container } = renderElements(<Footer />, componentContext);
expect(container).toMatchInlineSnapshot(`
<div>
<div>
Custom TypingIndicator
</div>
</div>
`);
});
});

describe('messageRenderer', () => {
const virtuosoIndex = PREPEND_OFFSET;
const numItemsPrepended = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ exports[`VirtualizedMessageList should render the list without any message 1`] =
No chats here yet…
</p>
</div>
<div />
</div>
</div>
</div>
Expand Down

0 comments on commit 4fce8e5

Please sign in to comment.