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

fix(Checkbox): no onChange/onClick when disabled #601

Merged
merged 4 commits into from
Oct 4, 2016

Conversation

sprmn
Copy link
Contributor

@sprmn sprmn commented Oct 3, 2016

Check if disabled before calling onChange function.

Fixes #600

Check if `disabled` before calling onChange
@layershifter
Copy link
Member

@sprmn Thanks for PR!

Your addition failed because you don't spreaded disabled, you need do this:

- const { onChange, onClick, name, value } = this.props
+ const { onChange, onClick, disabled, name, value } = this.props

Could you add a test-case for this? In Checkbox-test.js in describe('onChange'', () => {

it('omitted when has disabled prop', () => {
  const click = () => mount(<Checkbox disabled onChange={spy} />).simulate('click')
  expect(click).to.not.throw()
})

@sprmn
Copy link
Contributor Author

sprmn commented Oct 3, 2016

Oops, thought that it was already spread, but that was in the canToggle function, my bad.
I'll fix it and add a test case.

@layershifter
Copy link
Member

You can run tests with npm run test:watch and linter npm run lint:fix 👍

@codecov-io
Copy link

codecov-io commented Oct 3, 2016

Current coverage is 100% (diff: 100%)

Merging #601 into master will not change coverage

@@           master   #601   diff @@
====================================
  Files         119    119          
  Lines        1915   1915          
  Methods         0      0          
  Messages        0      0          
  Branches        0      0          
====================================
  Hits         1915   1915          
  Misses          0      0          
  Partials        0      0          

Powered by Codecov. Last update 6c72147...483862e

@jeffcarbs
Copy link
Member

jeffcarbs commented Oct 3, 2016

A few things:

  • There are props for disabled and readOnly but they're not being applied as classes. They should add the disabled and read-only classes respectively. Let's also add specs for those:
  common.propKeyOnlyToClassName(Checkbox, 'disabled')
  common.propKeyOnlyToClassName(Checkbox, 'readOnly', {
    className: 'read-only',
  })
  • There's already a method to determine if the checkbox can be toggled - canToggle. We're currently only using it to determine if we should try to update the checked state, but I think we should also use that to prevent the click/change handlers. So:
-    if (onClick) onClick(e, { name, value, checked: !!checked })
-    if (onChange) onChange(e, { name, value, checked: !checked })
-
     if (this.canToggle()) {
+      if (onClick) onClick(e, { name, value, checked: !!checked })
+      if (onChange) onChange(e, { name, value, checked: !checked })
+
       this.trySetState({ checked: !checked })
     }

@sprmn
Copy link
Contributor Author

sprmn commented Oct 4, 2016

Even better! Should be fixed now.

Copy link
Member

@jeffcarbs jeffcarbs left a comment

Choose a reason for hiding this comment

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

Checked this out locally and works as expected, 👍 🚢 💨

@jeffcarbs
Copy link
Member

@levithomason - this is ready to merge when you are 👍

@levithomason levithomason changed the title fix(Checkbox): onChange is called if checkbox is disabled fix(Checkbox): no onChange/onClick when disabled Oct 4, 2016
@levithomason levithomason merged commit d3588ed into Semantic-Org:master Oct 4, 2016
@levithomason
Copy link
Member

Thanks for taking care of this guys! Released in semantic-ui-react@0.54.1.

@sprmn sprmn deleted the fix/disabled-checkbox branch October 5, 2016 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants