Skip to content

Commit

Permalink
fix: Scroll to top on path change (#3926)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyle-ssg authored May 14, 2024
1 parent 185bd6a commit 1a2e793
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions frontend/web/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import SegmentsIcon from './svg/SegmentsIcon'
import AuditLogIcon from './svg/AuditLogIcon'
import Permission from 'common/providers/Permission'
import HomeAside from './pages/HomeAside'
import ScrollToTop from './ScrollToTop';

const App = class extends Component {
static propTypes = {
Expand Down Expand Up @@ -710,6 +711,7 @@ const App = class extends Component {
)
}}
</AccountProvider>
<ScrollToTop/>
</Provider>
)
}
Expand Down
16 changes: 16 additions & 0 deletions frontend/web/components/ScrollToTop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { FC, useEffect } from 'react'
import { withRouter } from 'react-router-dom'
import { RouteComponentProps } from 'react-router'

type ScrollToTopType = RouteComponentProps & {}

const ScrollToTop: FC<ScrollToTopType> = (props) => {
const pathname = props.location.pathname
useEffect(() => {
window.scrollTo(0, 0)
}, [pathname])

return null
}

export default withRouter(ScrollToTop)

0 comments on commit 1a2e793

Please sign in to comment.