Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Popover Nested Scrolling #365

Merged
merged 8 commits into from
Oct 30, 2019
Merged

Conversation

alexpaxton
Copy link
Contributor

@alexpaxton alexpaxton commented Oct 30, 2019

Closes #364

Changes

  • Set the event listener that PopoverDialog uses to maintain position to allow event bubbling
  • Add a couple stories that allow crude testing of Popover combined with DapperScrollbars
  • Use IntersectionObserver to hide Popover when its trigger scrolls out of view

Screenshots

popover-scroll-fix-2

Checklist

Check all that apply

  • Updated documentation to reflect changes
  • Added entry to top of Changelog with link to PR (not issue)
  • Tests pass
  • Peer reviewed and approved
  • Signed CLA (if not already signed)

@alexpaxton alexpaxton requested a review from a team October 30, 2019 16:47
@ghost ghost requested review from desa and zoesteinkamp and removed request for a team October 30, 2019 16:47
Copy link

@desa desa left a comment

Choose a reason for hiding this comment

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

Just a couple questions. More for my own learning.

const hidePopoverWhenOutOfView = (
entries: IntersectionObserverEntry[]
): void => {
if (!entries.length) {
Copy link

Choose a reason for hiding this comment

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

Super nit-picky, but I think this function could be simplified to be

if (!!entries.length && entries[0].isIntersecting === false ) {
  onHide()
}

useLayoutEffect((): (() => void) => {
handleUpdateStyles()
window.addEventListener('scroll', handleUpdateStyles)
observer.observe(triggerRef.current)
window.addEventListener('scroll', handleUpdateStyles, true)
Copy link

Choose a reason for hiding this comment

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

What does the true do here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Took me a whole day to figure out, but scroll events do not bubble by default. Adding this third argument in forces them to bubble

Copy link

Choose a reason for hiding this comment

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

Can you add a comment explaining that?

window.addEventListener('resize', handleUpdateStyles)

return (): void => {
observer.disconnect()
Copy link

Choose a reason for hiding this comment

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

What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might not be necessary, but I threw it in there so the observer stops observing as a sort of "cleanup"

@alexpaxton alexpaxton merged commit e6ff243 into master Oct 30, 2019
@alexpaxton alexpaxton deleted the bugfix/popover-nested-scroll branch October 30, 2019 17:09
@alexpaxton alexpaxton restored the bugfix/popover-nested-scroll branch October 30, 2019 17:09
@alexpaxton alexpaxton deleted the bugfix/popover-nested-scroll branch October 30, 2019 17:09
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Popover detached when trigger element is within a scrollable element
2 participants