-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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): prevent click propagation from the input element #3435
Changes from 2 commits
8b6c4a8
8f02615
eca6f52
d73360b
52b8f47
f4242e9
5837fc3
58d8a93
a7d98a3
96211aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -201,6 +201,50 @@ describe('Checkbox', () => { | |||||
}) | ||||||
}) | ||||||
|
||||||
describe('click propagation', () => { | ||||||
const assertions = [ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, I'll change that |
||||||
{ | ||||||
description: 'propagates once on "label" without "id"', | ||||||
id: undefined, | ||||||
target: 'label', | ||||||
propagates: true, | ||||||
}, | ||||||
{ | ||||||
description: 'does not propagate on "input" without "id"', | ||||||
id: undefined, | ||||||
target: 'input', | ||||||
propagates: false, | ||||||
}, | ||||||
{ | ||||||
description: 'propagates once on "label" with "id"', | ||||||
id: 'foo', | ||||||
target: 'label', | ||||||
propagates: true, | ||||||
}, | ||||||
{ | ||||||
description: 'does not propagate on "input" with "id"', | ||||||
id: 'foo', | ||||||
target: 'input', | ||||||
propagates: false, | ||||||
}, | ||||||
] | ||||||
|
||||||
assertions.forEach((assertion) => { | ||||||
it(assertion.description, () => { | ||||||
const onClick = sandbox.spy() | ||||||
wrapperMount( | ||||||
<div role='presentation' onClick={onClick}> | ||||||
<Checkbox id={assertion.id} /> | ||||||
</div>, | ||||||
) | ||||||
const target = document.querySelector(`.ui.checkbox ${assertion.target}`) | ||||||
domEvent.click(target) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -const target = document.querySelector(`.ui.checkbox ${assertion.target}`)
-domEvent.click(target)
+domEvent.click(`.ui.checkbox ${assertion.target}`)
This should be a valid change 😺 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know! |
||||||
if (assertion.propagates) onClick.should.have.been.calledOnce() | ||||||
else onClick.should.not.have.been.called() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -if (assertion.propagates) onClick.should.have.been.calledOnce()
-else onClick.should.not.have.been.called()
+onClick.should.have.callCount(Number(assertion.propagates)) We can test the call count directly, https://github.com/domenic/sinon-chai There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice idea! |
||||||
}) | ||||||
}) | ||||||
}) | ||||||
|
||||||
describe('label', () => { | ||||||
it('adds the "fitted" class when not present', () => { | ||||||
shallow(<Checkbox name='firstName' />).should.have.className('fitted') | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create a
handleInputClick
method and make a comment there with a link to the matching issue?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And sort props in alphabetic order ❤️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!