Skip to content

fix: keep model selector dropdown within viewport - #1496

Closed
Horizonll wants to merge 2 commits into
GCWing:mainfrom
Horizonll:main
Closed

fix: keep model selector dropdown within viewport#1496
Horizonll wants to merge 2 commits into
GCWing:mainfrom
Horizonll:main

Conversation

@Horizonll

@Horizonll Horizonll commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the model selector dropdown positioning so the model list stays fully visible when the app window is narrowed.

Fixes #1494

Type and Areas

Type:

bug fix / UI/UX

Areas:

web UI

Motivation / Impact

When the window width is reduced and the model selector is opened near the right edge, the dropdown was positioned from the trigger's left edge without clamping to the viewport. This could push the model list outside the visible window.

This change extracts the dropdown positioning calculation into a focused helper, clamps the dropdown width and horizontal position to the viewport, and lets narrow layouts shrink the menu while preserving text truncation.

Users can now open the model selector in narrow desktop windows without the list being cut off.

Verification

  • pnpm --dir src/web-ui run test:run src/flow_chat/components/modelSelectorDropdownPosition.test.ts
    • Passed: 1 file, 3 tests
  • pnpm run type-check:web
    • Passed
  • pnpm run build:web
    • Passed

Reviewer Notes

Checklist

  • This PR is focused and does not include secrets, temporary prompts, generated scratch files, or unrelated artifacts.
  • Relevant verification is recorded above, or skipped checks are explained.
  • User-facing strings, docs, and locales are updated where applicable.

Clamp the portal dropdown width and horizontal position to the viewport so the model list remains visible in narrow windows.

Verification:

- pnpm --dir src/web-ui run test:run src/flow_chat/components/modelSelectorDropdownPosition.test.ts

- pnpm run type-check:web

- pnpm run build:web
Copilot AI review requested due to automatic review settings July 10, 2026 06:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the Web UI model selector dropdown positioning in narrow windows by extracting a dedicated positioning helper that clamps the dropdown’s horizontal placement and width to the viewport, ensuring the menu stays fully visible near the right edge.

Changes:

  • Added getModelSelectorDropdownStyle helper to compute a fixed-position dropdown style with viewport clamping.
  • Updated ModelSelector to use the new helper for portal dropdown positioning on open/scroll/resize.
  • Adjusted dropdown SCSS to support shrinking layouts (including truncation/ellipsis behavior in the header and options).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/web-ui/src/flow_chat/components/modelSelectorDropdownPosition.ts New helper for dropdown width/left clamping and top/bottom placement style computation.
src/web-ui/src/flow_chat/components/modelSelectorDropdownPosition.test.ts Unit tests validating clamping behavior in narrow viewports and max-width scenarios.
src/web-ui/src/flow_chat/components/ModelSelector.tsx Switches runtime dropdown positioning logic to the new helper.
src/web-ui/src/flow_chat/components/ModelSelector.scss Updates dropdown sizing rules and improves truncation behavior for narrow widths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@limityan limityan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

审核结论:Request changes。当前实现解决了窄窗口右侧溢出,但引入了一个普通宽度下的可见回归,同时重复实现了仓库已有的 fixed-popover 定位逻辑。

1. 正常宽度下菜单被固定为 220px

问题

getModelSelectorDropdownStyle 使用触发器宽度计算菜单宽度。ChatInput 等调用点的触发器通常小于 220px,因此即使 viewport 很宽,菜单也始终得到 220px。

变更前使用 width: auto; min-width: 220px; max-width: 280px,长模型内容可以让菜单按内容扩展到 280px。

风险

这个窄窗口修复会让普通窗口下的长模型名、当前模式等内容更早截断,属于用户可见回归。现有测试只覆盖了新公式,没有保护原来的 220–280px 自适应行为。

建议

保留或测量菜单的 intrinsic width,只在 viewport 空间不足时收缩;补充“窄触发器 + 宽 viewport + 长内容”的回归测试。

2. 重复实现已有 fixed-popover 几何逻辑

问题

新增 helper 重新定义了 8px viewport padding、6px gap 和水平 clamp,但仓库已有 src/web-ui/src/shared/utils/fixedPopoverViewport.ts,并已被多个菜单使用。

风险

两套实现已经出现能力差异:共享实现支持垂直翻转,新实现只做水平约束。后续 viewport、缩放或短窗口修复需要维护两套规则,也不符合仓库对重复相似逻辑的约束。

建议

扩展共享工具为可注入 viewport/width 的纯几何 API;ModelSelector 仅负责菜单宽度策略和把共享计算结果转换成 CSSProperties。

已验证

  • 聚焦 Vitest:3/3 通过
  • pnpm run type-check:web:通过
  • git diff --check:通过
  • 当前 head 的 Frontend、Windows、macOS、Linux CI 均通过

CI 通过不覆盖上述宽度语义回归。修复两项问题并增加对应回归测试后再合并。

@Horizonll Horizonll closed this by deleting the head repository Jul 15, 2026
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.

[Bug]: 窗口宽度调小后模型选择列表显示不完整

3 participants