fix: fix issue with highlight code scrolling causing console error (#7497) (#7519)

Co-authored-by: Mahtis Michel <mathis.michel@outlook.de>

Refs #7497
This commit is contained in:
kristina-kovacikova
2021-10-05 09:27:57 +02:00
committed by GitHub
parent fc7cdb8bad
commit 24aaa53712

View File

@@ -39,6 +39,16 @@ export default class HighlightCode extends Component {
} }
} }
componentDidMount() {
[this.syntaxHighlighter, this.pre]
.map(element => element?.addEventListener("mousewheel", this.preventYScrollingBeyondElement, { passive: false }))
}
componentWillUnmount() {
[this.syntaxHighlighter, this.pre]
.map(element => element?.removeEventListener("mousewheel", this.preventYScrollingBeyondElement))
}
render () { render () {
let { value, className, downloadable, getConfigs, canCopy, language } = this.props let { value, className, downloadable, getConfigs, canCopy, language } = this.props
@@ -48,14 +58,14 @@ export default class HighlightCode extends Component {
const codeBlock = get(config, "syntaxHighlight.activated") const codeBlock = get(config, "syntaxHighlight.activated")
? <SyntaxHighlighter ? <SyntaxHighlighter
ref={elem => this.syntaxHighlighter = elem}
language={language} language={language}
className={className + " microlight"} className={className + " microlight"}
onWheel={this.preventYScrollingBeyondElement}
style={getStyle(get(config, "syntaxHighlight.theme"))} style={getStyle(get(config, "syntaxHighlight.theme"))}
> >
{value} {value}
</SyntaxHighlighter> </SyntaxHighlighter>
: <pre onWheel={this.preventYScrollingBeyondElement} className={className + " microlight"}>{value}</pre> : <pre ref={elem => this.pre = elem} className={className + " microlight"}>{value}</pre>
return ( return (
<div className="highlight-code"> <div className="highlight-code">