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

Add a scroll to top bottom #77

Merged
merged 4 commits into from Nov 7, 2020
Merged

Add a scroll to top bottom #77

merged 4 commits into from Nov 7, 2020

Conversation

tianlangwu
Copy link
Contributor

Fixed #76

Added a scrollToTop component with ScrollToTop.jsx and ScrollToTop.scss.
Imported and rendered ScrollToTop component in App component.

ezgif com-gif-maker

Let me know if I did anything incorrectly. Thanks for your consideration.

Copy link
Owner

@trybick trybick left a comment

Choose a reason for hiding this comment

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

The design and functionality are great! This will be a good addition.

One issue is on smaller screens the button overlaps the Next page button. Would it be easy to fix? (maybe move the button up higher on the page when the page is all the way scrolled down?)

Screen Shot 2020-11-06 at 5 09 42 PM

window.scrollTo({top: 0, behavior: 'smooth'});
};

window.addEventListener('scroll', checkScrollTop);
Copy link
Owner

Choose a reason for hiding this comment

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

Can we put the addEventListener into a useEffect? here are two examples:

https://gist.github.com/JoaoTMDias/b5aeb6e02be7e6d25d5fd7f10826fc8a

https://stackoverflow.com/a/58833641/9830506

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea , I will use useEffect to do that.

return (
<div className="scroll-to-top" onClick={scrollToTop}>
{showScroll &&
<div >
Copy link
Owner

Choose a reason for hiding this comment

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

nit - fix formatting and indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how to format here

Copy link
Owner

Choose a reason for hiding this comment

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

Instead of this

<div>
<Fab color="primary" aria-label="scroll back to top">
<ArrowUpIcon fontSize="large" />
</Fab>
</div>

more like this

<div>
  <Fab color="primary" aria-label="scroll back to top">
  <ArrowUpIcon fontSize="large" />
  </Fab>
</div>

You can also run the command npm run lint:fix to format everything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks!

import "./ScrollToTop.scss";

const ScrollArrow = () =>{

Copy link
Owner

Choose a reason for hiding this comment

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

nit - delete empty line

import './App.scss';


Copy link
Owner

Choose a reason for hiding this comment

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

we don't need this empty line

@tianlangwu
Copy link
Contributor Author

Is it ok that I push the button in the middle of the page?
image

@trybick
Copy link
Owner

trybick commented Nov 6, 2020

Instead of the middle, is it possible to keep it at the bottom, but above the other buttons?

@tianlangwu
Copy link
Contributor Author

Instead of the middle, is it possible to keep it at the bottom, but above the other buttons?

to prevent overlapping on the smallest screen, the lowest position is here. I am not sure it's prettier than the middle.
image

@tianlangwu
Copy link
Contributor Author

Instead of the middle, is it possible to keep it at the bottom, but above the other buttons?

Maybe I can add some responsive CSS, let me try

width: 56px;
height: 56px;
bottom: 22%;
right: 5%;
Copy link
Owner

Choose a reason for hiding this comment

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

media query is great! I played with the numbers and I think these make the position a little lower and centered above the other button. Can you try this?

bottom: 11%;
right: 7.5%

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, but I can't do it today. I will fix them tmr.

Copy link
Owner

Choose a reason for hiding this comment

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

No rush :)

import ArrowUpIcon from '@material-ui/icons/ArrowUpward';
import './ScrollToTop.scss';

const ScrollArrow = () => {
Copy link
Owner

Choose a reason for hiding this comment

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

could we rename to ScrollToTopButton?

const ScrollArrow = () => {
const [showScroll, setShowScroll] = useState(false);

const checkScrollTop = () => {
Copy link
Owner

Choose a reason for hiding this comment

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

could we rename to getShouldShowButton?

@trybick
Copy link
Owner

trybick commented Nov 7, 2020

Thanks @tianlangwu !

@trybick trybick merged commit 2961e70 into trybick:master Nov 7, 2020
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.

Add a scroll to top button.
2 participants