Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render typing indicator outside the VirtualizedMessageList scroll container #2406

Merged
merged 4 commits into from
Jun 3, 2024
Merged
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
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
Loading