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

feat: add Scroll to Top button #50

Merged
merged 14 commits into from
Aug 25, 2023

Conversation

jrachelr
Copy link
Collaborator

PR Checklist

Overview

Previously if a search returned multiple pages of results the user needed to manually scroll to return to the search form.

These changes add a scroll to top button component to improve UI.

How ScrollButton works:

  • setState hook for [visible, setVisible] is set to false
  • document.body.addEventListener("scroll", toggleVisible, { passive: true }) listens for the scroll event and sets the passive option to true to improve performance.
  • toggleVisible function references document.body using the built in scrollTop property and updates state to visible after scrolling >100 pixels, rendering the button in the DOM
  • The scrollToTop function uses the built in browser method scrollTo to scroll to the top: 0 coordinate of document.body.
  • scrollToTop is called when the button is clicked by the user with a onClick event handler

@vercel
Copy link

vercel bot commented Aug 25, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tidelift-me-up-site ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 25, 2023 6:12pm

Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

we're talking right now so todo will post actual thoughts hello hi

src/components/ScrollButton.tsx Show resolved Hide resolved
src/components/ScrollButton.module.css Show resolved Hide resolved
src/components/ScrollButton.tsx Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author Needs an action taken by the original poster label Aug 25, 2023
@JoshuaKGoldberg JoshuaKGoldberg self-requested a review August 25, 2023 19:31
@JoshuaKGoldberg JoshuaKGoldberg removed the status: waiting for author Needs an action taken by the original poster label Aug 25, 2023
Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

This is looking great, thanks! ✨ - it works, it looks nice, and it even has some snazzy horizontal sliding. Just requesting a couple UI fixups and some code things.

src/app/page.tsx Show resolved Hide resolved
src/components/ScrollButton.module.css Show resolved Hide resolved
src/components/ScrollButton.module.css Show resolved Hide resolved
src/components/ScrollButton.tsx Show resolved Hide resolved
src/components/ScrollButton.tsx Show resolved Hide resolved
src/app/page.tsx Show resolved Hide resolved
@JoshuaKGoldberg JoshuaKGoldberg added the status: waiting for author Needs an action taken by the original poster label Aug 25, 2023
@jrachelr jrachelr changed the title Feat/scroll to top +feat: add Scroll to Top button Aug 25, 2023
@jrachelr jrachelr changed the title +feat: add Scroll to Top button feat: add Scroll to Top button Aug 25, 2023
@JoshuaKGoldberg JoshuaKGoldberg removed the status: waiting for author Needs an action taken by the original poster label Aug 25, 2023
Copy link
Owner

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

💯 this is great, thanks!

I'll post followup issues after. Feel free to get started on them if you want in the meantime, but no rush.

Really excited about this - thanks @jrachelr! 🚀

Will Ferrel saying 'awesome' in a grocery store and punching cereal

@JoshuaKGoldberg JoshuaKGoldberg merged commit 7b5b5aa into JoshuaKGoldberg:main Aug 25, 2023
@JoshuaKGoldberg
Copy link
Owner

@all-contributors please add @JoshuaKGoldberg for maintenance.

🤖 Beep boop! This comment was added automatically by all-contributors-auto-action.
Not all contributions can be detected from Git & GitHub alone. Please comment any missing contribution types this bot missed.
...and of course, thank you for contributing! 💙

@allcontributors
Copy link
Contributor

@JoshuaKGoldberg

I've updated the pull request to add @JoshuaKGoldberg! 🎉

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

Repository owner deleted a comment from allcontributors bot Aug 27, 2023
@JoshuaKGoldberg
Copy link
Owner

@allcontributors add @jrachelr for feat

@allcontributors
Copy link
Contributor

@JoshuaKGoldberg

I couldn't determine any contributions to add, did you specify any contributions?
Please make sure to use valid contribution names.

@JoshuaKGoldberg
Copy link
Owner

@allcontributors add @jrachelr for code

@allcontributors
Copy link
Contributor

@JoshuaKGoldberg

I've put up a pull request to add @jrachelr! 🎉

JoshuaKGoldberg pushed a commit that referenced this pull request Aug 27, 2023
Adds @jrachelr as a contributor for code.

This was requested by JoshuaKGoldberg [in this
comment](#50 (comment))

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
@JoshuaKGoldberg
Copy link
Owner

@allcontributors add @jrachelr for design

@allcontributors
Copy link
Contributor

@JoshuaKGoldberg

I've put up a pull request to add @jrachelr! 🎉

JoshuaKGoldberg pushed a commit that referenced this pull request Aug 27, 2023
Adds @jrachelr as a contributor for design.

This was requested by JoshuaKGoldberg [in this
comment](#50 (comment))

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
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.

🚀 Feature: Add a 'back to top' button for long search results
2 participants