fix(mobile): prevent onboarding tooltip from overflowing screen

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
empty
2026-02-03 23:12:44 +08:00
parent 65b153e5df
commit 655f77ec3e

View File

@@ -46,7 +46,7 @@ const highlightStyle = computed(() => {
}; };
}); });
// Tooltip position // Tooltip position with boundary check
const tooltipStyle = computed(() => { const tooltipStyle = computed(() => {
const step = props.steps[props.currentStep]; const step = props.steps[props.currentStep];
if (!step) return {}; if (!step) return {};
@@ -63,24 +63,41 @@ const tooltipStyle = computed(() => {
const pos = step.position || 'bottom'; const pos = step.position || 'bottom';
const rect = targetRect.value; const rect = targetRect.value;
const gap = 16; const gap = 16;
const margin = 16; // Screen edge margin
const tooltipWidth = 300;
const screenWidth = window.innerWidth;
// Calculate horizontal position with boundary check
function getHorizontalPosition() {
const centerX = rect.left + rect.width / 2;
let left = centerX - tooltipWidth / 2;
// Check left boundary
if (left < margin) {
left = margin;
}
// Check right boundary
if (left + tooltipWidth > screenWidth - margin) {
left = screenWidth - margin - tooltipWidth;
}
return `${left}px`;
}
switch (pos) { switch (pos) {
case 'top': case 'top':
return { return {
bottom: `${window.innerHeight - rect.top + gap}px`, bottom: `${window.innerHeight - rect.top + gap}px`,
left: `${rect.left + rect.width / 2}px`, left: getHorizontalPosition(),
transform: 'translateX(-50%)',
}; };
case 'bottom': case 'bottom':
return { return {
top: `${rect.bottom + gap}px`, top: `${rect.bottom + gap}px`,
left: `${rect.left + rect.width / 2}px`, left: getHorizontalPosition(),
transform: 'translateX(-50%)',
}; };
case 'left': case 'left':
return { return {
top: `${rect.top + rect.height / 2}px`, top: `${rect.top + rect.height / 2}px`,
right: `${window.innerWidth - rect.left + gap}px`, right: `${screenWidth - rect.left + gap}px`,
transform: 'translateY(-50%)', transform: 'translateY(-50%)',
}; };
case 'right': case 'right':