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

bugfix/14080-bubblelegend-prevent-default-click #18765

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 42 additions & 0 deletions samples/unit-tests/bubble-legend/layout/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,48 @@ QUnit.test('Bubble legend ranges', function (assert) {
true,
'Bubble legend was properly disabled with the legend'
);

chart.addSeries({
type: 'bubble',
data: [
[1, 4, 4],
[2, 5, 5]
],
events: {
legendItemClick(e) {
e.preventDefault();
}
}
}, false);

chart.legend.update({
enabled: true,
floating: false
});

chart.series[1].legendItem.group.element.dispatchEvent(new Event('click'));
chart.series[0].legendItem.group.element.dispatchEvent(new Event('click'));

assert.ok(
true,
`There shouldn't be any error in the console, when one series
legendItemClick has prevented the event and we click both legend
items (#14080).`
);

assert.notOk(
isNaN(chart.legend.bubbleLegend.legendItem.labelHeight),
`Bubble legend should work correctly, when one series
legendItemClick has prevented the event and we click both legend
items (#14080).`
);

assert.notOk(
isNaN(chart.legend.bubbleLegend.legendItem.labelWidth),
`Bubble legend should work correctly, when one series
legendItemClick has prevented the event and we click both legend
items (#14080).`
);
});

QUnit.test('Negative values (#9678)', function (assert) {
Expand Down
4 changes: 3 additions & 1 deletion ts/Core/Foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ namespace Foundation {

if (isFunction(event)) {
component.eventOptions[eventType] = event;
addEvent(component, eventType, event);
addEvent(component, eventType, event, {
order: 0 // #14080 fire those events as firsts
TorsteinHonsi marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion ts/Series/Bubble/BubbleLegendComposition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ function onLegendAfterGetAllItems(
/**
* Toggle bubble legend depending on the visible status of bubble series.
*/
function onSeriesLegendItemClick(this: Series): void {
function onSeriesLegendItemClick(this: Series, e: any): void | boolean {
// #14080 don't fire this code if click function is prevented
if (e.defaultPrevented) {
return false;
}

const series = this,
chart = series.chart,
visible = series.visible,
Expand Down