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

doc engine: fix scroll bar for the content sidebar #1284

Merged
merged 9 commits into from
May 21, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix scrolling when no scroll in block
iKBAHT committed May 19, 2020

Verified

This commit was signed with the committer’s verified signature.
pompon0 Grzegorz Prusak
commit 3d771c4f51b0ea46085bbcfff55b179fc0fe0951
21 changes: 17 additions & 4 deletions src/components/Documentation/RightPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'
import React, { useState, useEffect, useRef } from 'react'
import cn from 'classnames'
import throttle from 'lodash/throttle'

@@ -91,15 +91,28 @@ const RightPanel: React.FC<IRightPanelProps> = ({
useEffect(initHeadingsPosition, [headings])
useEffect(updateCurrentHeader, [headingsOffsets, documentHeight])

const contentBlockRef = useRef<HTMLDivElement>(null)
const [
isScrollToCurrentHeadingHappened,
setIsScrollToCurrentHeadingHappened
] = useState(false)
useEffect(() => {
if (currentHeadingSlug && !isScrollToCurrentHeadingHappened) {
const el = document.getElementById(`link-${currentHeadingSlug}`)
el?.scrollIntoView()
setIsScrollToCurrentHeadingHappened(true)
const currentHeadingSlugElem = document.getElementById(
`link-${currentHeadingSlug}`
)
const contentBlockElem = contentBlockRef.current
if (currentHeadingSlugElem && contentBlockElem) {
const hasVerticalScrollbar =
contentBlockElem.scrollHeight > contentBlockElem.clientHeight
if (hasVerticalScrollbar) {
currentHeadingSlugElem.scrollIntoView({
block: 'start',
inline: 'nearest'
})
}
}
}
})

@@ -111,7 +124,7 @@ const RightPanel: React.FC<IRightPanelProps> = ({
<h5 className={styles.header}>Content</h5>
<hr className={styles.separator} />
</div>
<div className={styles.contentBlock}>
<div className={styles.contentBlock} ref={contentBlockRef}>
{headings.map(({ slug, text }) => (
<div id={`link-${slug}`} key={`link-${slug}`}>
<Link