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 #4290 and #4289: Time component scroll issue #4296

Conversation

balajis-qb
Copy link

@balajis-qb balajis-qb commented Oct 7, 2023

Closes #4290 and #4289

Summary
This PR addresses an issue where the Time component scroll position was not accurate to the selected time, especially when the last option in the Time list got selected. The fix ensures that the time component scrolls to the correct selected time item. This PR will also fix the issue #4289 where the selected time is not getting auto scrolled when we use portalId

Changes Made

  • Added the scroll logic inside the requestAnimationFrame method to schedule the scroll position update, ensuring that it occurs after the next repaint, when the DOM should be updated.
  • Ensures the availability of the list ref before using it inside requestAnimationFrame callback. By checking the ref availability, the issue of rendering failures is resolved, particularly during testing with asynchronous behavior.
  • Updated the time_format_test.test.js tests to reflect the changes made on the Time component, by adding await waitFor(() => ...)
    to wait for an element an element to appear in the DOM and then make assertions.

Balaji Sridharan added 3 commits October 6, 2023 22:25
This commit addresses an issue where the scroll position was not accurately set when the component mounted.  To resolve this, we have incorporated the use of requestAnimationFrame to delay the scroll update until after the component has fully rendered and layout calculations are complete.  This ensures consistent and precise scroll behavior.

Closes Hacker0x01#4290
In the time component, the scroll position is set using requestAnimationFrame. To ensure the accurate testing, this commit updates the test case to use waitFor from React Testing Library, allowing the test to wait for the scroll update to complete before making assertions about the scroll position.  The test now provides more reliable results and ensures that the scroll behavior is properly tested.

Closes Hacker0x01#4290
…Frame

In the Time component, this commit refactors the code to ensure that the component ref is available when used inside a requestAnimationFrame callback.  By checking the ref availability, the issue of rendering failures is resolved, particularly during testing with asynchronous behavior.

Closes Hacker0x01#4290
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

✅ This pull request was sent to the PullRequest network.


@balajis-qb you can click here to see the review status or cancel the code review job.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

PullRequest Breakdown

Reviewable lines of change

+ 61
- 34

75% JavaScript (tests)
25% JavaScript

Type of change

Fix - These changes are likely to be fixing a bug or issue.

@codecov
Copy link

codecov bot commented Oct 7, 2023

Codecov Report

Merging #4296 (967abca) into main (27788f5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 967abca differs from pull request most recent head efeeccc. Consider uploading reports for the commit efeeccc to get more accurate results

@@           Coverage Diff           @@
##             main    #4296   +/-   ##
=======================================
  Coverage   96.52%   96.52%           
=======================================
  Files          25       25           
  Lines        2358     2362    +4     
  Branches      962      963    +1     
=======================================
+ Hits         2276     2280    +4     
  Misses         82       82           
Files Coverage Δ
src/time.jsx 90.09% <100.00%> (+0.37%) ⬆️

@balajis-qb balajis-qb changed the title Fix #4290: Last item not fully visible when scrolling in time list Fix #4290 and #4289: Last item not fully visible when scrolling in time list Oct 7, 2023
@balajis-qb balajis-qb changed the title Fix #4290 and #4289: Last item not fully visible when scrolling in time list Fix #4290 and #4289: Time component scroll issue Oct 7, 2023
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

Thanks for writing such a great PR description. It looks like the scroll logic changes and async tests should do what's expected.

Image of Dallas Dallas


Reviewed with ❤️ by PullRequest

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

overall changes look good and consistent with the described changes. Testing has been updated as appropriate, no issues are noted.

Image of David K David K


Reviewed with ❤️ by PullRequest

Copy link
Member

@martijnrusschen martijnrusschen left a comment

Choose a reason for hiding this comment

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

Thanks for the fix and extensive writeup.

: this.list.clientHeight,
this.centerLi,
);
this.scrollToTheSelectedTime();
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for extracting this logic

@martijnrusschen martijnrusschen merged commit 64d750a into Hacker0x01:main Oct 8, 2023
4 checks passed
@balajis-qb
Copy link
Author

Thank you for the review and approving my PR

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.

Last item not fully visible when scrolling in time when using portalId in scrollable div
2 participants