File tree Expand file tree Collapse file tree
apps/web-dashboard/src/components/Layout Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { useState , useEffect } from 'react' ;
2+
23function BackToTop ( ) {
34 const [ isVisible , setIsVisible ] = useState ( false ) ;
5+
46 useEffect ( ( ) => {
57 const handleScroll = ( ) => {
68 if ( window . scrollY > 300 ) {
@@ -9,24 +11,30 @@ function BackToTop() {
911 setIsVisible ( false ) ;
1012 }
1113 } ;
14+
1215 window . addEventListener ( 'scroll' , handleScroll ) ;
16+
1317 return ( ) => {
1418 window . removeEventListener ( 'scroll' , handleScroll ) ;
1519 } ;
1620 } , [ ] ) ;
21+
1722 const handleClick = ( ) => {
1823 window . scrollTo ( {
1924 top : 0 ,
2025 behavior : 'smooth'
2126 } ) ;
2227 } ;
28+
2329 if ( ! isVisible ) {
2430 return null ;
2531 }
32+
2633 return (
2734 < button
2835 onClick = { handleClick }
2936 title = "Back to Top"
37+ aria-label = "Back to Top"
3038 style = { {
3139 position : 'fixed' ,
3240 bottom : '2rem' ,
@@ -50,4 +58,5 @@ function BackToTop() {
5058 </ button >
5159 ) ;
5260}
61+
5362export default BackToTop ;
You can’t perform that action at this time.
0 commit comments