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

fix: highlight code scroll console error (#7497) #7519

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