Skip to content

fix: add touch device detection for menu interaction - #9782

Open
mantoujun12 wants to merge 5 commits into
AstrBotDevs:masterfrom
mantoujun12:fix/9781
Open

fix: add touch device detection for menu interaction#9782
mantoujun12 wants to merge 5 commits into
AstrBotDevs:masterfrom
mantoujun12:fix/9781

Conversation

@mantoujun12

@mantoujun12 mantoujun12 commented Aug 23, 2026

Copy link
Copy Markdown

Modifications / 改动点

Fixes #9781

Chat.vue 中添加了两处内容

  • 添加了 isTouchDevice 变量,使用 CSS媒体查询 ,来判断是鼠标 (fine) 还是 触控 (coarse)
  • 修改了 AstrBot Web UI 中的 Chat UI 的 “通信传输模式” 和“语言” ,为 open-on-click 添加了 "!isTouchDevice" 判断,为 open-on-hover 添加了 "isTouchDevice" 判断
为什么要添加 isTouchDevice 变量

如果直接在原来的 <v-menu> 上添加 open-on-click 事件而不添加判断,在桌面端 Chat UI,点击 “通信传输模式” 和“语言” 会出现交互冲突。
具体情况是: 同时相应悬浮事件和点击事件。

使用 CSS 媒体查询判断操作设备有问题吗

正常情况下没有,因为 window.matchMedia 是通过读取用户的主要指针设备。
非特殊情况下,基本能正确识别是否是鼠标还是手指。
只有在极少数情况 (触摸笔、触控板等非常规指针输入设备) 可能会出现问题。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Before / 改动前

由于移动端触摸屏不会产生 hover 事件,点击 ”通信传输模式” 和”语言“ 没有任何响应。

Screenshot_2026-08-23-11-52-30-071_mark via

After / 改动后

为 ”通信传输模式” 和”语言“ 添加了 open-on-click 事件并添加判断。
并通过 "isTouchDevice" 变量判断用户指针输入设备是否为触控操作。
如果是,在移动端点击会直接弹出二级菜单,并且无交互问题。
并且为桌面端使用的 open-on-hover 也添加了判断条件,如果是鼠标则继续使用该方法,不会有冲突影响。

Screenshot_2026-08-23-11-52-21-095_mark via

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Improve Chat UI menu interaction across touch and desktop devices by enabling click-based expansion when touch input is detected.

Bug Fixes:

  • Enable the Chat UI’s Transport Mode and Language menus to open by click on touch devices, making their options accessible on mobile and touchscreen interfaces.

Enhancements:

  • Preserve hover-based menu interaction while adding touch-device detection for click-based expansion.

Summary by Sourcery

Adapt Chat UI menu interaction to the user’s primary pointer type so transport mode and language options work consistently across touch and desktop devices.

Bug Fixes:

  • Enable the Chat UI’s transport mode and language menus to open reliably on touch devices.

Enhancements:

  • Preserve hover-based menu interaction on pointer-based desktop devices while avoiding click and hover interaction conflicts.

Removed the open-on-hover of the Chat UI part of the AstrBot Web UI, and fixed the issue that the mobile end could not open the secondary menu of Transport Mode and Language.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. feature:chatui The bug / feature is about astrbot's chatui, webchat labels Aug 23, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 24, 2026
@mantoujun12

Copy link
Copy Markdown
Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mantoujun12 mantoujun12 changed the title fix: remove open-on-hover attribute from menu components fix: add touch device detection for menu interaction Aug 24, 2026
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Aug 24, 2026
@mantoujun12

Copy link
Copy Markdown
Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@mantoujun12

This comment was marked as resolved.

@mantoujun12

Copy link
Copy Markdown
Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="dashboard/src/components/chat/Chat.vue" line_range="823" />
<code_context>
     : "sse",
 );
+
+const isTouchDevice: boolean = window.matchMedia('(pointer: coarse)').matches;
+
 const transportOptions: Array<{ value: TransportMode; labelKey: string }> = [
</code_context>
<issue_to_address>
**issue (bug_risk):** On hybrid touchscreen devices whose primary pointer is reported as `fine` (for example, a laptop with both a mouse and touchscreen), `matchMedia('(pointer: coarse)')` returns false even when the user taps the screen. Both menus therefore disable click opening and rely on hover, but a touch tap does not produce the required hover event, so the Transport Mode and Language menus remain inaccessible.

**Triggers:** When a touchscreen device also has a fine primary pointer, or the available primary input changes after the component is initialized.

**Suggested fix:** Detect any available coarse pointer (for example, with `(any-pointer: coarse)` or `navigator.maxTouchPoints`) and keep the result reactive if the media-query match changes.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: dashboard/src/components/chat/Chat.vue:823


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dashboard/src/components/chat/Chat.vue Outdated

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="dashboard/src/components/chat/Chat.vue" line_range="823" />
<code_context>
     : "sse",
 );
+
+const isTouchDevice: boolean = window.matchMedia('(pointer: coarse)').matches;
+
 const transportOptions: Array<{ value: TransportMode; labelKey: string }> = [
</code_context>
<issue_to_address>
**issue (bug_risk):** `isTouchDevice` is a one-time snapshot of `matchMedia(...).matches`, so the menu interaction mode never changes after setup when the available primary pointer changes; attaching or removing a mouse/trackpad leaves the menus in the stale click-only or hover-only mode until the component is recreated or the page reloads.

**Triggers:** When a hybrid device changes its active or primary pointer during an open page session.

**Suggested fix:** Store the media query result in a reactive ref and update it from the `MediaQueryList` change event, removing the listener on component unmount.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: dashboard/src/components/chat/Chat.vue:823


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread dashboard/src/components/chat/Chat.vue Outdated
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Aug 24, 2026
@mantoujun12

Copy link
Copy Markdown
Author

@sourcery-ai review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. feature:chatui The bug / feature is about astrbot's chatui, webchat size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 移动端 Web UI 打开 Chat UI ,选项无法正常弹出二级菜单

1 participant