Skip to content

Commit 8fa76a7

Browse files
fix(website): fix hash scrolling
1 parent 23ed8bf commit 8fa76a7

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

packages/overmind-website/src/components/App/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Guide from '../Guide'
99
import Videos from '../Videos'
1010
import Api from '../Api'
1111
import MobileTopBar from '../MobileTopBar'
12-
import { useIsMobile, useScrollToTop } from '../../utils'
12+
import { useIsMobile, useScrollToPosition } from '../../utils'
1313
import Footer from '../Footer'
1414

1515
const pages = {
@@ -35,7 +35,7 @@ const App: SFC = () => {
3535
const { state } = useOvermind()
3636
const mainRef = useRef(null)
3737
const isMobile = useIsMobile()
38-
useScrollToTop(state.page)
38+
useScrollToPosition(state.page)
3939
useEffect(() => {
4040
fadeInPage()
4141
mainRef.current.style.opacity = '1'

packages/overmind-website/src/components/Doc/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { createElement, SFC } from 'react'
22
import * as styles from './styles'
3-
import { useScrollToTop } from '../../utils'
3+
import { useScrollToPosition } from '../../utils'
44

55
type Props = {
66
url: string
77
}
88

99
const Doc: SFC<Props> = ({ url, children }) => {
10-
useScrollToTop(url)
10+
useScrollToPosition(url)
1111

1212
return (
1313
<div className={styles.content}>

packages/overmind-website/src/utils.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,15 @@ export const useIsMobile = () => {
209209
return isMobile
210210
}
211211

212-
export const useScrollToTop = (value) => {
212+
export const useScrollToPosition = (value) => {
213213
useEffect(
214214
() => {
215215
document.querySelector('#overmind-app').scrollTop = 0
216+
217+
if (location.hash) {
218+
const hashElement = document.querySelector(location.hash)
219+
hashElement && hashElement.scrollIntoView()
220+
}
216221
},
217222
[value]
218223
)

0 commit comments

Comments
 (0)