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

No scroll to selected item when using portalId for showTimeSelectOnly in scrollable div #4289

Closed
1Jesper1 opened this issue Oct 5, 2023 · 5 comments

Comments

@1Jesper1
Copy link

1Jesper1 commented Oct 5, 2023

Describe the bug
No scroll to selected item when using portalId for showTimeSelectOnly in scrollable div

**Test code:

() => {
  const [startDate, setStartDate] = useState(new Date('02-02=2023 06:00'));
  return (
  <div>
  <div id='test'></div>
    <DatePicker
      portalId={'test'}
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      showTimeSelectOnly
      showTimeSelect
    />
     </div>
  );
};

**Possible fix:

onCalendarOpen={() => {
 const itemSelected = document.querySelector( '#datepicker-wrapper .react-datepicker__time-list-item--selected' );
 const offSetTop = itemSelected?.offsetTop;
 const clientHeight = itemSelected?.clientHeight;
 const parentElement = itemSelected?.parentElement;
 if (parentElement) {
    parentElement.scrollTop = offSetTop - ((parentElement.clientHeight / 2) - (clientHeight / 2));
 }
}};

Expected behavior
Should scroll to item.

**Screenshot
image

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome
  • Version react-datepicker 4.10.0
@1Jesper1 1Jesper1 changed the title No scroll to selected item when using portalId for showTimeSelectOnly No scroll to selected item when using portalId for showTimeSelectOnly in scrollable div Oct 5, 2023
@balajis-qb
Copy link

Hi,

I fixed the issue in my PR #4296 . This PR also fixes the other scroll related issue #4290. Kindly review my fix and let me know your review comments.

martijnrusschen added a commit that referenced this issue Oct 8, 2023
…em-scroll-issue

Fix #4290 and #4289: Time component scroll issue
@1Jesper1
Copy link
Author

1Jesper1 commented Oct 9, 2023

@martijnrusschen Nice to see a fix so soon available! This issue can be closed I think?

@martijnrusschen
Copy link
Member

You can close this issue if you're not experiencing issues anymore since the recent release

@1Jesper1
Copy link
Author

1Jesper1 commented Oct 9, 2023

@martijnrusschen I will test soon.

@1Jesper1
Copy link
Author

1Jesper1 commented Oct 9, 2023

Works!

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

No branches or pull requests

3 participants