Vibe Design Tips

空间不足时,各类浮层组件的处理方式

Overlay Avoidance

空间不足时,各类浮层组件的处理方式

组件交互

浮层避让的核心是先划定可用范围再动态定位:涵盖菜单翻转与限高、弹窗头尾常驻、Tooltip 八向换位与跟随回差、避开吸顶吸底固定栏 4 条交互准则及可交互演示。

Tooltip、菜单、弹窗这类浮层组件,内部内容长度不定,客户端与网页视窗的尺寸也不固定——这是 AI 生成界面时极易忽略的细节。若浮层只会朝单一固定方向展开,一旦触发器靠近视窗边缘、处于长列表底部或滚入吸顶栏下方,浮层就会被视窗裁切,或遮挡关键操作。稳妥的做法是先划定浮层的「可用范围」:视窗四边各内缩 16px,页面内的非模态浮层再额外扣除吸顶导航与吸底固定栏;同时通过 Portal 挂载到顶层避免父容器裁切,并在每次打开、滚动、窗口缩放及自身尺寸变化时动态重算位置。

放不下就翻转,超长就限高

菜单默认在触发器下方 8px 处展开。当下方空间不足而上方充裕时,应自动翻转改为向上展开;级联子菜单在右侧放不下时同理翻至左侧,展开动画的起点(transform-origin)也同步切到贴近触发器的一侧。若翻转后侧向仍有超出,沿视窗边缘平移回安全区内;若菜单总高度仍超出当前侧的可用高度,则将容器最大高度限制在可用范围内,改为内部滚动,并在截断边缘做渐隐过渡以提示下方仍有内容。此外,唤起菜单后若光标在菜单外滚动页面,说明用户视线已回到主界面,应让菜单即刻淡出收起。

  • 适用场景:下拉菜单、右键菜单、级联子菜单、选择器(Select)
  • 参数:距视窗边缘 16px,距触发器 8px,按「翻转 → 平移 → 限高滚动」依次处理;菜单外滚动即刻淡出

弹窗头尾常驻

当弹窗承载较长内容时,若直接按内容高度居中撑开,标题行与底部操作行会被推到视窗之外,用户既看不清当前上下文,也找不到确认按钮。应将弹窗最大高度限制在视窗安全高度内,固定标题栏与底部操作栏,仅让中间内容区滚动,并在内容滚入标题下方时浮现一条 1px 分隔线。若某一场景的内容经常较多,建议改用抽屉代替弹窗——桌面端使用侧滑抽屉,移动端直接使用自下而上延展的通栏底部抽屉。

  • 适用场景:长列表弹窗、设置面板、表单弹窗、协议确认
  • 参数:上下各留 16px,标题行与底部操作行固定,内容滚动后标题下显示 1px 分隔线;内容常长时改用侧边或移动端通栏抽屉

Tooltip 换向与跟随回差

当 Tooltip 超出视窗边缘时,应翻转至另一方向;若仅靠近侧边局部超出,也可将浮层沿边缘平移回范围内,并让箭头始终指向触发器中心。带箭头的 Tooltip 可预设上、下、左、右及四角共 8 个方位,根据距各边缘的剩余空间动态择优。对于图表中跟随光标移动的气泡,默认放在光标右下方并完全让出光标本身;靠近右边缘时翻至光标左侧,往回移动时则需比换边位置再向内多退 24px 才换回右侧,借助「回差」避免光标停在边界附近时气泡反复跳动。提示框、跟随气泡与抽屉的选型边界,详见 009 提示框、气泡、抽屉与弹窗怎么选。

  • 适用场景:图标按钮与头像 Tooltip、图表读数气泡、跟随光标的信息卡
  • 参数:带箭头设 8 个方向动态选择,平移时箭头对准触发器中心;跟随气泡让出光标,换回回差 24px

避开吸顶与吸底固定栏

任意非模态浮层——尤其是 Tooltip、下拉菜单与 Toast——都应避开固定吸顶与吸底的元素容器(如顶部导航栏、底部播放条、Tab 栏、聊天输入框),计算可用范围时先将这些固定栏占用的高度扣除。Toast 应停在底部固定栏上方,避免盖住播放控件或主导航;滚动时不主动关闭的浮层,一旦触发器随页面滚入吸顶导航下方,应随之同步隐藏,而非悬空压在导航栏上。模态弹窗因带有遮罩接管全局操作,可覆盖顶底固定栏,其可用范围按整个视窗计算。

  • 适用场景:吸顶导航与吸底栏周边的 Tooltip、下拉菜单、底部播放条 / Tab 栏 / 输入框上方的 Toast
  • 参数:可用范围扣除顶底固定栏,Toast 距底部栏 16px,触发器被吸顶栏遮挡时浮层同步隐藏

交给 AI 来做

将下方 Prompt 复制给 Claude Code、Codex、Cursor、WorkBuddy 等 AI 工具:它会先盘点项目现有的菜单、气泡、Tooltip、Toast 与弹窗组件,找出边缘裁切与固定栏遮挡问题并列成表格;等你确认后,直接在组件层补齐翻转、平移、限高与避让逻辑。

Prompt复制后发给 Claude Code、Codex、Cursor、WorkBuddy 等 Agent
Check the overlay components my product already has (menus and dropdowns, popovers, tooltips, toasts and dialogs), find where each one breaks at the extremes (by an edge of the window, low on a long page, under a sticky header, above a fixed bottom bar, with long content), and fix the cause in the component, so every place that uses it gets the fix. Diagnose first, and change only what I approve. Work inside my code and components, and do not add a dependency without asking. Every value below is a default to start from.

0. Diagnose
- List each overlay component, where it is defined (my own, or a library: Floating UI, Radix, MUI, Ant Design), and how it is placed today: preferred side, offset, whether it flips, shifts or caps its height, what it measures against, whether it is rendered in a portal, and when it places itself again.
- Find what stays fixed on screen (sticky headers, bottom bars) and any clipping or scrolling container between an overlay and the window.
- Find the places where each one fails: the last rows of a long list, the right end of a header, inside a scrolling panel, a dialog with its longest content. Trace each failure to its cause in the component, not to the page it shows up on.

1. The room
- Every overlay stays inside the window less 16px on each side. In the page, also less the sticky header and any fixed bottom bar; modal layers cover the bars. Render overlays in a portal.
- Place it again on open, on scroll, on resize and when its own size changes, not once only.

2. Menus and dropdowns
- 8px from the trigger. When the preferred side has no room, flip to the other side, then shift along it into the room.
- When it is still too tall, cap it to the room and let it scroll inside.
- When the page scrolls while the pointer is outside the menu, fade it out and close it.
- With Floating UI: offset(8), flip, shift and size with padding 16, and autoUpdate.

3. Dialogs
- No taller than the window less 16px. The title bar and the button bar stay put; only the content between them scrolls, with a 1px line where it passes under them.
- Where the content is often long, suggest a side drawer on desktop and a full-width bottom sheet on phones, and ask me before changing.

4. Tooltips
- By an edge, flip to the opposite side or shift along it; the arrow keeps pointing at the trigger.
- With an arrow, choose among 8 placements (above, below, left, right and the four corners) by the room on each side.
- A tooltip that follows the pointer sits clear of the cursor, moves to its other side by an edge, and comes back only once the pointer is 24px further in.

5. Fixed bars
- No overlay, tooltips above all, covers a sticky header or a bottom bar. Toasts sit 16px above the bottom bar. An overlay whose trigger scrolls under the header hides with it.

6. Report and check
- Before changing anything, give me one table, one row per component: | Component | Used in | Today | Cases that fail | Cause | Fix | Values |. Ask me which rows to change.
- Afterwards, go back to every failing case and check that it opens whole, inside the room.