Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/updatemenus/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ function drawButtons(gd, gHeader, gButton, menuOpts) {
setActive(gd, menuOpts, buttonOpts, gHeader, gButton, buttonIndex);

Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);

gd.emit('plotly_buttonclicked', {menu: menuOpts, button: buttonOpts, active: menuOpts.active});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some people have been asking for an event on legend item click.

I'm not suggesting we should have a lone event for updatemenu button click and legend item click, but we should make sure the event names are consistent.

I'm thinking plotly_buttonclicked and plotly_legendclick, unless someone find the two confusing.

});

button.on('mouseover', function() {
Expand Down
25 changes: 25 additions & 0 deletions test/jasmine/tests/updatemenus_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,31 @@ describe('update menus interactions', function() {
});
});

it('should emit an event on button click', function(done) {
var clickCnt = 0;
var data = [];
gd.on('plotly_buttonclicked', function(datum) {
data.push(datum);
clickCnt++;
});

click(selectHeader(0)).then(function() {
expect(clickCnt).toEqual(0);

return click(selectButton(2));
}).then(function() {
expect(clickCnt).toEqual(1);
expect(data.length).toEqual(1);
expect(data[0].active).toEqual(2);

return click(selectButton(1));
}).then(function() {
expect(clickCnt).toEqual(2);
expect(data.length).toEqual(2);
expect(data[1].active).toEqual(1);
}).catch(fail).then(done);
});

it('should apply update on button click', function(done) {
var header0 = selectHeader(0),
header1 = selectHeader(1);
Expand Down