Skip to content

[dev-v5][Popover] React to ViewPort changes#4884

Open
MarvinKlein1508 wants to merge 1 commit into
microsoft:dev-v5from
MarvinKlein1508:react-viewport-changes
Open

[dev-v5][Popover] React to ViewPort changes#4884
MarvinKlein1508 wants to merge 1 commit into
microsoft:dev-v5from
MarvinKlein1508:react-viewport-changes

Conversation

@MarvinKlein1508
Copy link
Copy Markdown
Collaborator

Pull Request

📖 Description

This PR is a follow-up for #4872 and #4882. It enhances the FluentPopover component by reacting to changes with to the viewPort by attaching scroll and resize event handlers to the FluentPopover. This event handlers recalculate the position for the current view port.

This improves the component use-age in scenarios where virtual keyboards are being displayed or hided like in FluentAutocomplete.

Before:

WhatsApp.Video.2026-05-21.at.14.59.05.mp4

After:

WhatsApp.Video.2026-05-21.at.14.59.07.mp4

I have tested this changes in Firefox, Chrome, Edge and on Safari both on macOS and iOS.

🎫 Issues

Fixes #4878

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

  • I have added a new component
  • I have added Unit Tests for my new component
  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

⏭ Next Steps

@MarvinKlein1508 MarvinKlein1508 requested a review from vnbaaij as a code owner May 21, 2026 13:03
Copilot AI review requested due to automatic review settings May 21, 2026 13:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves popover positioning behavior on viewport changes (notably iOS visual viewport/keyboard changes) by listening to visualViewport events, throttling reposition work to the next animation frame, and adjusting placement calculations to account for visual viewport offsets.

Changes:

  • Add visualViewport scroll/resize listeners alongside existing window listeners.
  • Debounce/reduce repeated reposition calls via requestAnimationFrame (and cancel any pending frame on disconnect).
  • Update “available space” calculations to incorporate visual viewport top/left offsets.

Comment on lines +314 to +317
const spaceAbove = rect.top - viewportTop;
const spaceBelow = viewportBottom - rect.bottom;
const spaceLeft = rect.right - viewportLeft;
const spaceRight = viewportRight - rect.left;
Comment on lines 68 to +71
window.addEventListener('scroll', this.handleWindowChange, true);
window.addEventListener('resize', this.handleWindowChange, true);
window.visualViewport?.addEventListener('scroll', this.handleWindowChange);
window.visualViewport?.addEventListener('resize', this.handleWindowChange);
Comment on lines 67 to 72
connectedCallback() {
window.addEventListener('scroll', this.handleWindowChange, true);
window.addEventListener('resize', this.handleWindowChange, true);
window.visualViewport?.addEventListener('scroll', this.handleWindowChange);
window.visualViewport?.addEventListener('resize', this.handleWindowChange);
}
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.

2 participants