addListener and removeListener are only invoked on defined (and valid) values (#11685)

This commit is contained in:
Arun Philip 2024-02-28 10:55:52 -05:00 committed by GitHub
parent 4068bd8c47
commit bbdaa6a14b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -95,12 +95,16 @@ function initCanvas(canvas, aspectRatio) {
const eventListenerOptions = supportsEventListenerOptions ? {passive: true} : false;
function addListener(node, type, listener) {
if (node) {
node.addEventListener(type, listener, eventListenerOptions);
}
}
function removeListener(chart, type, listener) {
if (chart && chart.canvas) {
chart.canvas.removeEventListener(type, listener, eventListenerOptions);
}
}
function fromNativeEvent(event, chart) {
const type = EVENT_TYPES[event.type] || event.type;