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
Conversation
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.
window.scrollTo({top: 0, behavior: 'smooth'}); | ||
}; | ||
|
||
window.addEventListener('scroll', checkScrollTop); |
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.
Can we put the addEventListener into a useEffect? here are two examples:
https://gist.github.com/JoaoTMDias/b5aeb6e02be7e6d25d5fd7f10826fc8a
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.
yea , I will use useEffect to do that.
return ( | ||
<div className="scroll-to-top" onClick={scrollToTop}> | ||
{showScroll && | ||
<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.
nit - fix formatting and indentation
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 am not sure how to format here
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.
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
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.
thanks!
import "./ScrollToTop.scss"; | ||
|
||
const ScrollArrow = () =>{ | ||
|
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.
nit - delete empty line
src/components/App.jsx
Outdated
import './App.scss'; | ||
|
||
|
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.
we don't need this empty line
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%; |
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.
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%
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.
sure, but I can't do it today. I will fix them tmr.
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.
No rush :)
import ArrowUpIcon from '@material-ui/icons/ArrowUpward'; | ||
import './ScrollToTop.scss'; | ||
|
||
const ScrollArrow = () => { |
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.
could we rename to ScrollToTopButton
?
const ScrollArrow = () => { | ||
const [showScroll, setShowScroll] = useState(false); | ||
|
||
const checkScrollTop = () => { |
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.
could we rename to getShouldShowButton
?
Thanks @tianlangwu ! |
Fixed #76
Added a scrollToTop component with
ScrollToTop.jsx
andScrollToTop.scss
.Imported and rendered ScrollToTop component in App component.
Let me know if I did anything incorrectly. Thanks for your consideration.