Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(Popover): move position with target when in scroll container #2749

Merged
merged 2 commits into from
Jun 27, 2023

Conversation

jrood
Copy link
Contributor

@jrood jrood commented Jun 9, 2023

Overview

Move popover position with target when in a scroll container

We currently handle repositioning the popover so that it moves with the target when a user scrolls at the window level. However, we were not handling scrolling if the popover was within a container that scrolls while the window scroll is stationary (e.g. for narrative content on the LE). This PR introduces behavior to find the parent/ancestor element that is scrollable and ensure that the popover position is updated each time a scroll event is fired on that parent element.

PR Checklist

  • Related to designs for Docs LE Tooltips
  • Related to JIRA ticket: REACH-2716
  • I have run this code to verify it works
  • This PR includes unit tests for the code change
  • This PR includes testing instructions tests for the code change
  • The alpha package of this PR is passing end-to-end tests in all relevant Codecademy repositories

Testing Instructions

  • Open packages/styleguide/stories/Molecules/Popover/Popover.examples.tsx
  • Edit the PopoverExample so that it returns something in a scroll container, e.g.
return (
  <div style={{overflow: 'auto', maxHeight: '200px' }}>
    {'abcde'.split('').map(x => <div>{x}</div>)}
    <Box ref={activeElRef}>
      <FillButton onClick={toggleOpen}>Open Popover</FillButton>
    </Box>
    <FlexBox>
      <Popover
        {...rest}
        isOpen={open}
        targetRef={activeElRef}
        onRequestClose={() => setOpen(false)}
      >
        <FlexBox flexDirection="column" p={p} alignItems="flex-start">
          <Box mb={8}>Hooray!</Box>
          <FillButton size="small" onClick={() => setOpen(false)}>
            Close Popover
          </FillButton>
        </FlexBox>
      </Popover>
    </FlexBox>
    {'abcde'.split('').map(x => <div>{x}</div>)}
  </div>
);

PR Links and Envs

Repository PR Link PR Env
Monolith Monolith PR Monolith Preview Env
Monorepo Monorepo PR Portal Preview Env
LE Preview Env

@jrood jrood requested review from a team, jakemhiller, BandanaKM and dreamwasp and removed request for a team June 12, 2023 16:06
@jrood jrood marked this pull request as ready for review June 13, 2023 13:15
Copy link
Contributor

@dreamwasp dreamwasp left a comment

Choose a reason for hiding this comment

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

all lgtm so far - can you link where this is used in the LE so i can test the fix in context?

@jrood
Copy link
Contributor Author

jrood commented Jun 20, 2023

@dreamwasp for sure. If you go to the Learn SQL course and tab onto the first "SQL" link, you should see a Docs tooltip. If you scroll while that tooltip is open, it will move with the target with this fix (https://tayra.codecademy.com/courses/learn-sql/lessons/manipulation/exercises/sql?PR_ENV=le-pr-2330) but not in prod (https://www.codecademy.com/courses/learn-sql/lessons/manipulation/exercises/sql)

@jrood jrood force-pushed the jrood.REACH-2716.move-popover-in-scroll-container branch from a5c20fa to addc71c Compare June 23, 2023 22:10
@codecademydev
Copy link
Collaborator

📬Published Alpha Packages:

@codecademy/[email protected]
@codecademy/[email protected]
@codecademy/[email protected]
@codecademy/[email protected]
@codecademy/[email protected]

@codecademydev
Copy link
Collaborator

🚀 Styleguide deploy preview ready!

https://64961aa4f7eb8207dd56bab9--gamut-preview.netlify.app

Deploy Logs

Copy link
Contributor

@dreamwasp dreamwasp left a comment

Choose a reason for hiding this comment

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

noticed a small bug when you scroll to the top of the container but that being said, this is a huge improvement on the current behavior so am down for you to ship as is even if you can't tweak it. great work!

Screen.Recording.2023-06-27.at.11.26.48.AM.mov

@jrood jrood added the Ship It :shipit: Automerge this PR when possible label Jun 27, 2023
@codecademydev codecademydev merged commit 184c8d4 into main Jun 27, 2023
12 of 13 checks passed
@codecademydev codecademydev deleted the jrood.REACH-2716.move-popover-in-scroll-container branch June 27, 2023 15:50
@codecademydev codecademydev removed the Ship It :shipit: Automerge this PR when possible label Jun 27, 2023
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.

3 participants