Repository navigation
Conversation
The final position was clamped with Math.max(top, 0) / Math.max(left, 0) only, so a bubble that overflowed the right edge stayed off-screen while the left edge was already handled. calcPlacement can only flip the placement when the opposite side fits, so a wide bubble centred on its trigger still ran off the right edge. Extract the horizontal clamp into clampHorizontal and bound it by windowWidth - contentWidth. Content wider than the viewport is pinned to the left edge so its beginning stays visible. Fixes Tencent#4197
lnuxe
requested review from
anlyyao,
betavs,
jarmywang,
jin0209,
novlan1 and
zydemail
as code owners
November 23, 2026 03:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 这个 PR 的性质是?
🔗 相关 Issue
Fixes #4197
💡 需求背景和解决方案
问题:气泡超出左侧屏幕时会紧靠左侧(
Math.max(left, 0)),但超出右侧时没有对应处理,气泡会跑到屏幕外。calcPlacement只能在「对侧放得下」时翻转 placement(triggerLeft - contentWidth >= 0之类)。当一个气泡比触发元素宽很多、又居中对齐触发元素时,两侧都放不下,翻转也就无从谈起,最终直接越出右边缘。修复前的最终定位:
只有下界,没有上界。
解决方案:把横向夹取抽成纯函数
clampHorizontal(left, contentWidth, windowWidth),用windowWidth - contentWidth作为上界:纵向没有一起改:竖向越界由
calcPlacement翻转 placement 处理,本次只补齐 issue 指出的横向缺口,避免影响现有纵向布局。回归测试(
packages/components/popover/__test__/utils.test.js):(100, 50, 375)(-20, 100, 375)(360, 100, 375)(50, 500, 375)修复前:
Tests: 2 failed, 2 passed(Expected: 275 / Received: 360,Expected: 0 / Received: 50);修复后:Tests: 4 passed。全量单测:
147 suites / 883 tests / 410 snapshots全部通过;eslint干净。📝 更新日志
tdesign-miniprogram