diff --git a/src/LaddaButton.jsx b/src/LaddaButton.jsx index f1f43dd..cff9854 100644 --- a/src/LaddaButton.jsx +++ b/src/LaddaButton.jsx @@ -29,6 +29,7 @@ class LaddaButton extends Component { className: PropTypes.string, progress: PropTypes.number, loading: PropTypes.bool, + disabled: PropTypes.bool, // Ladda props // eslint-disable-next-line react/no-unused-prop-types @@ -89,6 +90,7 @@ class LaddaButton extends Component { {...omit(this.props, OMITTED_PROPS)} className={`ladda-button ${this.props.className || ''}`} ref={this.setNode} + disabled={this.props.disabled || this.props.loading} > {this.props.children} diff --git a/test/LaddaButton-test.jsx b/test/LaddaButton-test.jsx index 4d54e13..ded615c 100644 --- a/test/LaddaButton-test.jsx +++ b/test/LaddaButton-test.jsx @@ -80,6 +80,21 @@ describe('LaddaButton', () => { expect(wrapper.html()).to.contain('ladda-progress') }) + it('should not disable the button if `props.loading` is falsey', () => { + const wrapper = mount() + expect(wrapper.find('button').prop('disabled')).to.eq(undefined) + }) + + it('should disable the button if the `props.disabled` is set', () => { + const wrapper = mount() + expect(wrapper.find('button').prop('disabled')).to.eq(true) + }) + + it('should disable the button if `props.loading` is truthy', () => { + const wrapper = mount() + expect(wrapper.find('button').prop('disabled')).to.eq(true) + }) + describe('ladda instance', () => { let createStub let laddaInstance @@ -143,7 +158,7 @@ describe('LaddaButton', () => { expect(laddaInstance.stop).not.to.have.been.called }) - context('when `progress` is initially set', () => { + context('when `props.progress` is initially set', () => { beforeEach(() => { mount() }) @@ -153,7 +168,7 @@ describe('LaddaButton', () => { }) }) - context('when `loading` is initially set to a truthy value', () => { + context('when `props.loading` is initially set', () => { beforeEach(() => { mount() })