Skip to content

Commit

Permalink
fix: fix issue with highlight code scrolling causing console error (#…
Browse files Browse the repository at this point in the history
…7497) (#7519)

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

Refs #7497
  • Loading branch information
kristina-kovacikova committed Oct 5, 2021
1 parent fc7cdb8 commit 24aaa53
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/core/components/highlight-code.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
let { value, className, downloadable, getConfigs, canCopy, language } = this.props

Expand All @@ -48,14 +58,14 @@ export default class HighlightCode extends Component {

const codeBlock = get(config, "syntaxHighlight.activated")
? <SyntaxHighlighter
ref={elem => this.syntaxHighlighter = elem}
language={language}
className={className + " microlight"}
onWheel={this.preventYScrollingBeyondElement}
style={getStyle(get(config, "syntaxHighlight.theme"))}
>
{value}
</SyntaxHighlighter>
: <pre onWheel={this.preventYScrollingBeyondElement} className={className + " microlight"}>{value}</pre>
: <pre ref={elem => this.pre = elem} className={className + " microlight"}>{value}</pre>

return (
<div className="highlight-code">
Expand Down

0 comments on commit 24aaa53

Please sign in to comment.