Skip to content

fix(core): clamp popovers to viewport#461

Merged
antfu merged 2 commits into
mainfrom
fix/floating-popover-position
Jul 23, 2026
Merged

fix(core): clamp popovers to viewport#461
antfu merged 2 commits into
mainfrom
fix/floating-popover-position

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Close #459

iShot_2026-07-23_10 11 38

Copilot AI review requested due to automatic review settings July 23, 2026 02:14
@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@461

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@461

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@461

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@461

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@461

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@461

commit: 3fba67c

Copilot AI 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.

Pull request overview

Fixes dock/tooltip popovers overflowing the viewport in embedded floating/edge dock modes by introducing viewport-aware positioning with panel-size measurement and adding targeted regression coverage.

Changes:

  • Refactors FloatingPopover to delegate positioning to a new resolveFloatingPosition() helper and measure panel dimensions for clamping.
  • Adds floating-position.ts resolver to handle alignment guessing, side flipping, and cross-axis clamping.
  • Adds Storybook coverage (corner anchors) and Vitest unit tests for the new positioning logic.

Reviewed changes

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

File Description
packages/core/src/client/webcomponents/components/floating/FloatingPopover.ts Measures popover size and uses shared resolver to compute styles, enabling clamped positioning.
packages/core/src/client/webcomponents/components/floating/FloatingPopover.stories.ts Adds a corner-anchor harness to visually validate viewport clamping.
packages/core/src/client/webcomponents/components/floating/floating-position.ts Introduces centralized positioning logic (guess/flip/clamp).
packages/core/src/client/webcomponents/components/floating/tests/floating-position.test.ts Adds unit tests covering alignment selection, flipping, clamping, and first-paint behavior.
Comments suppressed due to low confidence (1)

packages/core/src/client/webcomponents/components/floating/floating-position.ts:90

  • For left/right placements, the main axis position isn’t clamped even when panelWidth is known. This means wide popovers can still overflow past the viewport edge (especially when placement is explicit and flipping is disabled). Clamping the computed left/right keeps the popover within VIEWPORT_MARGIN.
  else {
    if (align === 'right')
      style.left = `${anchorRight + gap}px`
    else
      style.right = `${vw - rect.left + gap}px`

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

@antfu
antfu merged commit 0212826 into main Jul 23, 2026
10 checks passed
@antfu
antfu deleted the fix/floating-popover-position branch July 23, 2026 04:13
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.

Dock (float mode): hover labels overflow the viewport, making some entries unreachable

3 participants