diff --git a/cypress/integration/toolbar.spec.js b/cypress/integration/toolbar.spec.js index 8e55d890..db32ec88 100644 --- a/cypress/integration/toolbar.spec.js +++ b/cypress/integration/toolbar.spec.js @@ -449,4 +449,28 @@ describe('Testing the Toolbar', () => { .should('have.not.class', 'active'); }); }); + + it('Enable disabled button', () => { + let eventFired = ''; + cy.window().then(({ map }) => { + map.on('pm:buttonclick', ({ btnName }) => { + eventFired = btnName; + }); + map.pm.Toolbar.setButtonDisabled('drawPolygon', true); + }); + cy.toolbarButton('polygon') + .click() + .then(() => { + expect(eventFired).to.equal(''); + }); + + cy.window().then(({ map }) => { + map.pm.Toolbar.setButtonDisabled('drawPolygon', false); + }); + cy.toolbarButton('polygon') + .click() + .then(() => { + expect(eventFired).to.equal('drawPolygon'); + }); + }); }); diff --git a/src/js/Toolbar/L.Controls.js b/src/js/Toolbar/L.Controls.js index 7cc612ed..75759d80 100644 --- a/src/js/Toolbar/L.Controls.js +++ b/src/js/Toolbar/L.Controls.js @@ -270,6 +270,8 @@ const PMButton = L.Control.extend({ } else { L.DomUtil.removeClass(button, className); button.setAttribute('aria-disabled', 'false'); + L.DomEvent.on(button, 'click', this._triggerClick, this); + L.DomEvent.on(button, 'click', this._onBtnClick, this); } }, });