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: Fixed the problem of scrolling the message list while updating t… #2451

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

YyumeiZhang
Copy link
Collaborator

@YyumeiZhang YyumeiZhang commented Aug 26, 2024

…he message stream, and the message list would unexpectedly scroll to the bottom

中文模板 / Chinese Template

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Test Case
  • TypeScript definition update
  • Document improve
  • CI/CD improve
  • Branch sync
  • Other, please describe:

PR description

Fixes #

发送消息/接受消息,以及消息流式更新等场景中,无需显示滚动条,并且在内容更新时候,需要自动滚动到最底部;
但是在使用鼠标/触控板拖动等用户触发的滚动行为时,需要显示滚动条,此时如果同时存在消息流式更新场景,不应该将滚动条滚动到最底部来显示最新消息。

问题表现
用户滚动聊天框后,消息流式更新,会导致聊天框滚动到最底部显示最新信息,不符合预期。

问题原因
wheel 事件的 target 是鼠标/触控板滚动行为发生的元素。
预期是在 wheel 事件中检测用户是否执行滚动行为。但是判断的依据错误(wheel 事件的 event.target 和 event.currentTarget)

问题解决方案
实际发生滚动的元素可以通过聊天内容 container 中的 scroll 事件的 target 进行获取。在 scroll 事件中保存事件的target(scrollTarget),在container 的 wheel 事件中判断 scrollTarget 是否为 container(wheel 的 event.currentTarget),即可判断是否是用户触发了 container 的滚动,以此决定是否显示滚动条以及在回复的消息流式更新时候,是否需要滚动到最底部

Changelog

🇨🇳 Chinese

  • Fix: 修复 Chat 组件在消息流式更新的同时,滚动消息列表,消息流式更新会导致列表意外滚动到底部问题

🇺🇸 English

  • Fix: Fixed the issue where the Chat component scrolls the message list while the message is being updated streaming. The streaming update of message will cause the list to unexpectedly scroll to the bottom.

Checklist

  • Test or no need
  • Document or no need
  • Changelog or no need

Other

  • Skip Changelog

Additional information

…he message stream, and the message list would unexpectedly scroll to the bottom
Copy link

codesandbox-ci bot commented Aug 26, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9a6e74f:

Sandbox Source
pr-story Configuration

@DaiQiangReal DaiQiangReal merged commit 1a70b37 into main Aug 27, 2024
14 of 16 checks passed
@DaiQiangReal DaiQiangReal deleted the fix/chat-scroll branch August 27, 2024 04:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants