-
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
fix(Checkbox): prevent click propagation from the input element #3435
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3435 +/- ##
==========================================
+ Coverage 99.89% 99.89% +<.01%
==========================================
Files 172 172
Lines 2820 2830 +10
==========================================
+ Hits 2817 2827 +10
Misses 3 3
Continue to review full report at Codecov.
|
Actually we should check:
|
I can check that later, but just to confirm, the So if we're testing mount(
<div role='presentation' onClick={onClick}>
<Checkbox id='foo' />
</div>,
) We could also test mount(
<div role='presentation' onClick={onClick}>
<Checkbox />
</div>,
) Then it's all or nothing with the id, right? |
Absolutely const wrapperWithId = mount(
<div role='presentation' onClick={onClick}>
<Checkbox id='foo' />
</div>,
)
const wrapper = mount(
<div role='presentation' onClick={onClick}>
<Checkbox />
</div>,
)
wrapperWithId.find('input').click() // 1
wrapperWithId.find('label').click() // 2
wrapper.find('input').click() // 3
wrapper.find('label').click() // 4 |
Oh that's right, we set the |
Tests updated @layershifter ! |
</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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know!
const target = document.querySelector(`.ui.checkbox ${assertion.target}`) | ||
domEvent.click(target) | ||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea!
@@ -201,6 +201,50 @@ describe('Checkbox', () => { | |||
}) | |||
}) | |||
|
|||
describe('click propagation', () => { | |||
const assertions = [ |
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.
const assertions = [ | |
const assertMatrix= [ |
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.
Sure, I'll change that
src/modules/Checkbox/Checkbox.js
Outdated
@@ -258,6 +258,7 @@ export default class Checkbox extends Component { | |||
tabIndex={this.computeTabIndex()} | |||
type={type} | |||
value={value} | |||
onClick={e => e.stopPropagation()} |
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!
@Fabianopb I made some comments, can you please address them? Nice job 👍 |
Awesome @layershifter thanks for the comments, I'll try address them later today! |
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.
@layershifter I just pushed the changes!
src/modules/Checkbox/Checkbox.js
Outdated
@@ -258,6 +258,7 @@ export default class Checkbox extends Component { | |||
tabIndex={this.computeTabIndex()} | |||
type={type} | |||
value={value} | |||
onClick={e => e.stopPropagation()} |
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!
@@ -201,6 +201,50 @@ describe('Checkbox', () => { | |||
}) | |||
}) | |||
|
|||
describe('click propagation', () => { | |||
const assertions = [ |
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.
Sure, I'll change that
</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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know!
const target = document.querySelector(`.ui.checkbox ${assertion.target}`) | ||
domEvent.click(target) | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea!
…React into fix/checkbox-parent-click
@Fabianopb I added changes that I picked from @levithomason branch 😸 Can you please help to test these changes? Did I miss something? I.e. double clicks, event propagation, right mouse click? |
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.
@layershifter that looks good to me, just one detail I got from re-testing the behavior manually:
- without "id" the parent listens for a click coming necessarily from the
label
- with "id" the parent listens for a click coming necessarily from the
input
Is that ok/intended?
events: { | ||
label: ['mouseup', 'click'], | ||
input: ['click'], | ||
}, | ||
target: 'label', |
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.
This target
property doesn't seem to be used anymore, is that so?
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.
Nice catch 👍
…React into fix/checkbox-parent-click
For me it looks fine, I don't see a big issue. I've tested it again, works like a charm 💎 Thank you! |
@Fabianopb You've contributed here before and you've shown care and initiative for ensuring SUIR becomes better. We appreciate this and want to enable you to do more. I've added you as a collaborator. You're now able to manage issues and PRs as well as create branches here in the main repo. You no longer need to work from a fork. Merging to master is the only reserved permission. We are very select about who we add and when, so know that we trust your abilities and your judgment. Please feel free to weigh in on any issues and PRs that you have an opinion about. You have a share of ownership and say here now. Once you accept the invite (see your email), you might want to show the Semantic Org badge publicly on your profile. To do that, navigate to the "people" page and change the "private" dropdown to "public" for your user in the table. Here's a direct link to your user in the table. /cc Please welcome @Fabianopb to our ranks 😄 🎉 |
Released in |
Initially the click was being fired from both
label
andinput
Now it only comes from
label
(Closes #3433)
(Closes #3440)