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): handle click properly on label #3692

Merged
merged 1 commit into from
Jul 7, 2019
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
3 changes: 2 additions & 1 deletion src/modules/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ export default class Checkbox extends Component {
const { id } = this.props
const { checked, indeterminate } = this.state

const isLabelClick = _.invoke(this.labelRef.current, 'contains', e.target)
Copy link
Member Author

Choose a reason for hiding this comment

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

Previously there was an equality comparison, but in this case contains() should be used.


const hasId = !_.isNil(id)
const isLabelClick = e.target === this.labelRef.current
const isLabelClickAndForwardedToInput = isLabelClick && hasId

// https://github.com/Semantic-Org/Semantic-UI-React/pull/3351
Expand Down
10 changes: 10 additions & 0 deletions test/specs/modules/Checkbox/Checkbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ describe('Checkbox', () => {
wrapper.find('label').simulate('click')
onChange.should.have.not.been.called()
})

it('is called when click is done on nested element', () => {
const onChange = sandbox.spy()
wrapperMount(<Checkbox label={{ children: <span>Foo</span> }} onChange={onChange} />)

wrapper.find('span').simulate('mouseup')
wrapper.find('span').simulate('click')

onChange.should.have.been.calledOnce()
})
})

describe('onClick', () => {
Expand Down