Skip to content

Commit 24aaa53

Browse files
fix: fix issue with highlight code scrolling causing console error (#7497) (#7519)
Co-authored-by: Mahtis Michel <[email protected]> Refs #7497
1 parent fc7cdb8 commit 24aaa53

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/core/components/highlight-code.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ export default class HighlightCode extends Component {
3939
}
4040
}
4141

42+
componentDidMount() {
43+
[this.syntaxHighlighter, this.pre]
44+
.map(element => element?.addEventListener("mousewheel", this.preventYScrollingBeyondElement, { passive: false }))
45+
}
46+
47+
componentWillUnmount() {
48+
[this.syntaxHighlighter, this.pre]
49+
.map(element => element?.removeEventListener("mousewheel", this.preventYScrollingBeyondElement))
50+
}
51+
4252
render () {
4353
let { value, className, downloadable, getConfigs, canCopy, language } = this.props
4454

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

4959
const codeBlock = get(config, "syntaxHighlight.activated")
5060
? <SyntaxHighlighter
61+
ref={elem => this.syntaxHighlighter = elem}
5162
language={language}
5263
className={className + " microlight"}
53-
onWheel={this.preventYScrollingBeyondElement}
5464
style={getStyle(get(config, "syntaxHighlight.theme"))}
5565
>
5666
{value}
5767
</SyntaxHighlighter>
58-
: <pre onWheel={this.preventYScrollingBeyondElement} className={className + " microlight"}>{value}</pre>
68+
: <pre ref={elem => this.pre = elem} className={className + " microlight"}>{value}</pre>
5969

6070
return (
6171
<div className="highlight-code">

0 commit comments

Comments
 (0)