prevent HighlightCode from scrolling entire document

This commit is contained in:
Kyle Shockey
2018-04-12 17:52:27 -07:00
parent 0cdd54c24d
commit 64b83738ce
+24 -1
View File
@@ -26,6 +26,24 @@ export default class HighlightCode extends Component {
saveAs(fileToSave, "response")
}
preventYScrollingBeyondElement = (e) => {
const target = e.target
var deltaY = e.nativeEvent.deltaY
var contentHeight = target.scrollHeight
var visibleHeight = target.offsetHeight
var scrollTop = target.scrollTop
const scrollOffset = visibleHeight + scrollTop
const isScrollingPastTop = scrollTop === 0 && deltaY < 0
const isScrollingPastBottom = scrollOffset >= contentHeight && deltaY > 0
if (isScrollingPastTop || isScrollingPastBottom) {
e.preventDefault()
}
}
render () {
let { value, className } = this.props
className = className || ""
@@ -33,7 +51,12 @@ export default class HighlightCode extends Component {
return (
<div className="highlight-code">
<div className="download-contents" onClick={this.downloadJSON}>Download</div>
<pre ref={this.initializeComponent} className={className + " microlight"}>{value}</pre>
<pre
ref={this.initializeComponent}
onWheel={this.preventYScrollingBeyondElement}
className={className + " microlight"}>
{value}
</pre>
</div>
)
}