Skip to content

Commit

Permalink
Add scroll to top of the page after navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
iAdramelk committed Dec 4, 2019
1 parent ec21bc8 commit 2bb3d88
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pages/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React, { useCallback, useState, useEffect } from 'react'
import PropTypes from 'prop-types'
import Error from 'next/error'
import Router from 'next/router'
// components
import Page from '../src/Page'
import { HeadInjector } from '../src/Documentation/HeadInjector'
Expand All @@ -20,6 +21,7 @@ import sidebar, { getItemByPath } from '../src/Documentation/SidebarMenu/helper'
import styled from 'styled-components'
import { media } from '../src/styles'

const ROOT_ELEMENT = 'bodybag'
const SIDEBAR_MENU = 'sidebar-menu'

const parseHeadings = text => {
Expand Down Expand Up @@ -69,6 +71,19 @@ export default function Documentation({ item, headings, markdown, errorCode }) {
}
}, [isSearchAvaible])

useEffect(() => {
const handleRouteChange = () => {
const rootElement = document.getElementById(ROOT_ELEMENT)
if (rootElement) {
rootElement.scrollTop = 0
}
}

Router.events.on('routeChangeComplete', handleRouteChange)

return () => Router.events.off('routeChangeComplete', handleRouteChange)
}, [])

const githubLink = `https://github.com/iterative/dvc.org/blob/master${source}`

return (
Expand Down

0 comments on commit 2bb3d88

Please sign in to comment.