-
Notifications
You must be signed in to change notification settings - Fork 3
Scroll results into view when paginating #1189
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
Conversation
aa982ba to
937b322
Compare
rhysyngsun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality looks good, just one piece of feedback.
| setSearchParams, | ||
| }) => { | ||
| const [searchParams] = useSearchParams() | ||
| const scrollHook = useRef<HTMLInputElement>(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should just be HTMLElement because it's a div
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot, thanks.
rhysyngsun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| setTimeout(() => { | ||
| scrollHook.current?.scrollIntoView({ | ||
| block: "center", | ||
| behavior: "smooth", | ||
| }) | ||
| }, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity... why wrap this in setTimeout?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despite some investigating, all I can say for sure is that it doesn't work without it. Likely some nuance around the dom element not being available during the old render cycle.
What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/4741
Description (What does it do?)
Scrolls the top of the search results to the center of the page on pagination.
Screenshots (if appropriate):
Screen.Recording.2024-06-28.at.15.35.18.mov
How can this be tested?
Navigate to the search page or a unit page and paginate through search results.