Skip to content

fix(dropdown): close popover when parent container scrolls#9236

Open
faizkhairi wants to merge 1 commit intoopengovsg:developfrom
faizkhairi:fix/close-dropdown-on-scroll
Open

fix(dropdown): close popover when parent container scrolls#9236
faizkhairi wants to merge 1 commit intoopengovsg:developfrom
faizkhairi:fix/close-dropdown-on-scroll

Conversation

@faizkhairi
Copy link
Copy Markdown

Summary

  • Close dropdown popover when any scrollable ancestor scrolls, preventing it from appearing above the sticky header
  • Walks up the DOM tree to find all scrollable ancestors and attaches passive scroll listeners
  • Uses existing setIsFocused(false) to close the popover (same mechanism as outside-click handler)

Related Issue

Closes #6026

Approach

Rather than adjusting z-index (which just masks the problem), this fix closes the popover when the user scrolls. This matches the behavior expected by the maintainer as described in the feedback on the earlier PR #6501.

Changes

File Change
apps/frontend/src/components/Dropdown/components/SelectPopover/SelectPopover.tsx Add useEffect to close popover on ancestor scroll

Implementation Detail

The useEffect runs when isOpen becomes true. It walks parentElement up the DOM from the floating-ui reference element, checking getComputedStyle for overflow: auto/scroll on each ancestor. Each scrollable ancestor gets a passive scroll listener. The window also gets a listener for page-level scroll. All listeners are removed in the effect cleanup when isOpen becomes false or the component unmounts.

Test Plan

  • Open a dropdown in the form builder sidebar
  • Scroll the sidebar -- dropdown should close
  • Open a dropdown and scroll the page -- dropdown should close
  • Verify dropdown still works normally (open, select, close on click outside)
  • Verify no memory leaks (listeners cleaned up on unmount)

Add scroll event listeners to all scrollable ancestors of the dropdown
trigger. When any ancestor scrolls, the popover closes immediately.
This prevents the dropdown from appearing above the sticky header.
@faizkhairi faizkhairi requested a review from a team as a code owner March 24, 2026 18:29
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.

Dropdown options are rendered above the title sticky header when scrolling

1 participant