Skip to content

Commit d9442d2

Browse files
committed
fix: render typing indicator outside the VirtualizedMessageList scroll container (#2406)
BREAKING CHANGE: The VirtualizedMessageList does not provide default Footer component BREAKING CHANGE: The VirtualizedMessageList markup has changed as TypingIndicator is rendered as a child of MessageListMainPanel
1 parent 7bf63ae commit d9442d2

4 files changed

+3
-29
lines changed

src/components/MessageList/VirtualizedMessageList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
calculateFirstItemIndex,
3838
calculateItemIndex,
3939
EmptyPlaceholder,
40-
Footer,
4140
Header,
4241
Item,
4342
makeItemsRenderedHandler,
@@ -235,6 +234,7 @@ const VirtualizedMessageListWithContext = <
235234
UnreadMessagesNotification = DefaultUnreadMessagesNotification,
236235
UnreadMessagesSeparator,
237236
VirtualMessage: MessageUIComponentFromContext = MessageSimple,
237+
TypingIndicator,
238238
} = useComponentContext<StreamChatGenerics>('VirtualizedMessageList');
239239
const MessageUIComponent = MessageUIComponentFromProps || MessageUIComponentFromContext;
240240

@@ -439,7 +439,6 @@ const VirtualizedMessageListWithContext = <
439439
className='str-chat__message-list-scroll'
440440
components={{
441441
EmptyPlaceholder,
442-
Footer,
443442
Header,
444443
Item,
445444
...virtuosoComponentsFromProps,
@@ -495,6 +494,7 @@ const VirtualizedMessageListWithContext = <
495494
{...(defaultItemHeight ? { defaultItemHeight } : {})}
496495
/>
497496
</div>
497+
{TypingIndicator && <TypingIndicator />}
498498
</MessageListMainPanel>
499499
<MessageListNotifications
500500
hasNewMessages={newMessagesNotification}

src/components/MessageList/VirtualizedMessageListComponents.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ export const EmptyPlaceholder = <
108108
</>
109109
);
110110
};
111-
export const Footer = <
112-
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
113-
>() => {
114-
const { TypingIndicator } = useComponentContext<StreamChatGenerics>('VirtualizedMessageList');
115-
return TypingIndicator ? <TypingIndicator /> : null;
116-
};
111+
117112
export const messageRenderer = <
118113
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
119114
>(

src/components/MessageList/__tests__/VirtualizedMessageListComponents.test.js

-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import '@testing-library/jest-dom';
33
import { render, screen } from '@testing-library/react';
44
import {
55
EmptyPlaceholder,
6-
Footer,
76
Header,
87
Item,
98
messageRenderer,
@@ -207,25 +206,6 @@ describe('VirtualizedMessageComponents', () => {
207206
});
208207
});
209208

210-
describe('Footer', () => {
211-
it('should render nothing in Footer by default', () => {
212-
const { container } = renderElements(<Footer />);
213-
expect(container).toMatchInlineSnapshot(`<div />`);
214-
});
215-
it('should render custom TypingIndicator in Footer', () => {
216-
const TypingIndicator = () => <div>Custom TypingIndicator</div>;
217-
const componentContext = { TypingIndicator };
218-
const { container } = renderElements(<Footer />, componentContext);
219-
expect(container).toMatchInlineSnapshot(`
220-
<div>
221-
<div>
222-
Custom TypingIndicator
223-
</div>
224-
</div>
225-
`);
226-
});
227-
});
228-
229209
describe('messageRenderer', () => {
230210
const virtuosoIndex = PREPEND_OFFSET;
231211
const numItemsPrepended = 0;

src/components/MessageList/__tests__/__snapshots__/VirtualizedMessageList.test.js.snap

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ exports[`VirtualizedMessageList should render the list without any message 1`] =
6464
No chats here yet…
6565
</p>
6666
</div>
67-
<div />
6867
</div>
6968
</div>
7069
</div>

0 commit comments

Comments
 (0)