Skip to content

Commit

Permalink
Fix: limit chat scrolling to chat transcript container.
Browse files Browse the repository at this point in the history
  • Loading branch information
lublagg committed Dec 18, 2024
1 parent b0722df commit c779863
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/components/chat-transcript-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ export const ChatTranscriptMessage = ({message, showDebugLog}: IProps) => {
data-testid="chat-message"
role="listitem"
>
<h3 aria-label="speaker" data-testid="chat-message-speaker">
<h3 data-testid="chat-message-speaker">
{speaker}
</h3>
<div
aria-label="message"
className={`chat-message-content ${speakerClass}`}
data-testid="chat-message-content"
>
Expand Down
1 change: 0 additions & 1 deletion src/components/chat-transcript.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ describe("test chat transcript component", () => {
expect(speaker).toHaveTextContent(chatTranscript.messages[index].speaker);

const content = within(message).getByTestId("chat-message-content");
expect(content).toHaveAttribute("aria-label", "message");
expect(content).toHaveTextContent(chatTranscript.messages[index].messageContent.content);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/components/chat-transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export const ChatTranscriptComponent = observer(({chatTranscript, showDebugLog,
const chatTranscriptContainer = chatTranscriptRef.current;
if (chatTranscriptContainer) {
const lastMessage = chatTranscriptContainer.querySelector(".chat-transcript__message:last-of-type");
lastMessage?.scrollIntoView({behavior: "smooth"});
lastMessage?.scrollIntoView({behavior: "smooth", block: "nearest"});
}
}, [chatTranscript.messages.length]);
}, [chatTranscript.messages.length, isLoading]);

return (
<div ref={chatTranscriptRef} id="chat-transcript" className="chat-transcript" data-testid="chat-transcript" role="group">
Expand Down
7 changes: 3 additions & 4 deletions src/components/loading-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ import { timeStamp } from "../utils/utils";

export const LoadingMessage = () => {
return (
<section
<div
aria-label={`${DAVAI_SPEAKER} at ${timeStamp()}`}
className={`chat-transcript__message ${DAVAI_SPEAKER.toLowerCase()}`}
data-testid="chat-message"
role="listitem"
>
<h3 aria-label="speaker" data-testid="chat-message-speaker">
<h3 data-testid="chat-message-speaker">
{DAVAI_SPEAKER}
</h3>
<div
aria-label="message"
className={`chat-message-content ${DAVAI_SPEAKER.toLowerCase()}`}
data-testid="chat-message-content"
>
Expand All @@ -25,6 +24,6 @@ export const LoadingMessage = () => {
>
</div>
</div>
</section>
</div>
);
};

0 comments on commit c779863

Please sign in to comment.