Skip to content

Commit

Permalink
Disable button when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdir committed Jan 1, 2017
1 parent b715286 commit 1f558eb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/LaddaButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
>
<span className="ladda-label">
{this.props.children}
Expand Down
19 changes: 17 additions & 2 deletions test/LaddaButton-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<LaddaButton />)
expect(wrapper.find('button').prop('disabled')).to.eq(undefined)
})

it('should disable the button if the `props.disabled` is set', () => {
const wrapper = mount(<LaddaButton disabled />)
expect(wrapper.find('button').prop('disabled')).to.eq(true)
})

it('should disable the button if `props.loading` is truthy', () => {
const wrapper = mount(<LaddaButton loading />)
expect(wrapper.find('button').prop('disabled')).to.eq(true)
})

describe('ladda instance', () => {
let createStub
let laddaInstance
Expand Down Expand Up @@ -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(<LaddaButton progress={0.3} />)
})
Expand All @@ -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(<LaddaButton loading />)
})
Expand Down

0 comments on commit 1f558eb

Please sign in to comment.