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

fix: Scroll to top on path change #3926

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)