Skip to content

Commit 5577d94

Browse files
authored
fix: add workaround for checking correct target element (#10072)
1 parent b24e2b8 commit 5577d94

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/charts/src/vaadin-chart-mixin.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import 'highcharts/es-modules/masters/modules/xrange.src.js';
2828
import 'highcharts/es-modules/masters/modules/bullet.src.js';
2929
import 'highcharts/es-modules/masters/modules/gantt.src.js';
3030
import 'highcharts/es-modules/masters/modules/draggable-points.src.js';
31+
import KeyboardNavigation from 'highcharts/es-modules/Accessibility/KeyboardNavigation.js';
32+
import HTMLUtilities from 'highcharts/es-modules/Accessibility/Utils/HTMLUtilities.js';
3133
import Pointer from 'highcharts/es-modules/Core/Pointer.js';
3234
import Highcharts from 'highcharts/es-modules/masters/highstock.src.js';
3335
import { get } from '@vaadin/component-base/src/path-utils.js';
@@ -68,6 +70,35 @@ Pointer.prototype.onDocumentMouseMove = function (e) {
6870
}
6971
};
7072

73+
// As the `mouseup` event is attached to the document element, the target will reference
74+
// the instance of the `vaadin-chart` element instead of the element the event originated from.
75+
// That causes some mishbehaviors, e.g. in a drilldown series, clicking in the point does not
76+
// drills down the series in some cases.
77+
// Change to check for the first element in the composed path as the target of the event.
78+
// Workaround for https://github.com/highcharts/highcharts/issues/23490
79+
//
80+
// TODO: Remove this monkeypatch once the referenced issue is fixed
81+
const { simulatedEventTarget } = HTMLUtilities;
82+
KeyboardNavigation.prototype.onMouseUp = function (e) {
83+
delete this.isClickingChart;
84+
if (!this.keyboardReset && e.relatedTarget !== simulatedEventTarget) {
85+
const chart = this.chart;
86+
const target = e.composedPath()[0];
87+
if (!target || !chart.container.contains(target)) {
88+
const curMod = this.modules && this.modules[this.currentModuleIx || 0];
89+
if (curMod && curMod.terminate) {
90+
curMod.terminate();
91+
}
92+
this.currentModuleIx = 0;
93+
}
94+
if (chart.focusElement) {
95+
chart.focusElement.removeFocusBorder();
96+
delete chart.focusElement;
97+
}
98+
this.keyboardReset = true;
99+
}
100+
};
101+
71102
// Init Highcharts global language defaults
72103
// No data message should be empty by default
73104
Highcharts.setOptions({ lang: { noData: '' } });

0 commit comments

Comments
 (0)