fix(dropdown): close popover when parent container scrolls#9236
Open
faizkhairi wants to merge 1 commit intoopengovsg:developfrom
Open
fix(dropdown): close popover when parent container scrolls#9236faizkhairi wants to merge 1 commit intoopengovsg:developfrom
faizkhairi wants to merge 1 commit intoopengovsg:developfrom
Conversation
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.
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.
Summary
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
apps/frontend/src/components/Dropdown/components/SelectPopover/SelectPopover.tsxuseEffectto close popover on ancestor scrollImplementation Detail
The
useEffectruns whenisOpenbecomes true. It walksparentElementup the DOM from the floating-uireferenceelement, checkinggetComputedStyleforoverflow: auto/scrollon each ancestor. Each scrollable ancestor gets a passivescrolllistener. The window also gets a listener for page-level scroll. All listeners are removed in the effect cleanup whenisOpenbecomes false or the component unmounts.Test Plan