-
Notifications
You must be signed in to change notification settings - Fork 4k
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): onFocus and onBlur events #1361
fix(Checkbox): onFocus and onBlur events #1361
Conversation
Rather than adding callbacks, we need to set focus and add tests, see #1335 (comment). |
Codecov Report
@@ Coverage Diff @@
## master #1361 +/- ##
==========================================
+ Coverage 99.74% 99.74% +<.01%
==========================================
Files 141 141
Lines 2371 2376 +5
==========================================
+ Hits 2365 2370 +5
Misses 6 6
Continue to review full report at Codecov.
|
@layershifter does this look right? what about the blur event? |
I left a comment on the issue for the blur event. Let's get tests passing as well. |
Sweet thanks! For the test, we're simulating a |
Indeed. |
Since the Since we're now handling the prop, it also needs added to |
src/modules/Checkbox/Checkbox.js
Outdated
@@ -196,7 +200,10 @@ export default class Checkbox extends Component { | |||
else computedTabIndex = disabled ? -1 : 0 | |||
|
|||
return ( | |||
<ElementType {...rest} className={classes} onClick={this.handleClick} onChange={this.handleClick}> | |||
<ElementType {...rest} className={classes} | |||
onClick={this.handleClick} onChange={this.handleClick} |
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.
Need a line break between the props here.
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.
Still need the line break here 😉
- onClick={this.handleClick} onChange={this.handleClick}
+ onClick={this.handleClick}
+ onChange={this.handleClick}
you mean something like this @levithomason? |
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.
I've clarified the changes necessary here.
src/modules/Checkbox/Checkbox.js
Outdated
@@ -149,6 +149,10 @@ export default class Checkbox extends Component { | |||
} | |||
} | |||
|
|||
handleMouseDown = (e) => { | |||
_.invoke('focus', this.checkboxRef) |
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 is correct, however, we also need to call the user's onMouseDown
prop here if they provide one. That is because we handling the prop, so it isn't auto spread on the rendered component. Even if it were, we are also setting the onMouseDown event ourselves, so our handler is the only one that will ever be called.
So, if they pass:
<Checkbox onMouseDown={() => console.log('hi')} />
Then nothing will happen onMouseDown. To ensure they can also pass a onMouseDown
handler, we need to also call it in our handler for them. Since mouse down is called before the focus event, let's call it in the right order as well:
handleMouseDown = (e) => {
_.invoke('onMouseDown', this.props, [e])
_.invoke('focus', this.checkboxRef)
}
src/modules/Checkbox/Checkbox.js
Outdated
@@ -196,7 +200,10 @@ export default class Checkbox extends Component { | |||
else computedTabIndex = disabled ? -1 : 0 | |||
|
|||
return ( | |||
<ElementType {...rest} className={classes} onClick={this.handleClick} onChange={this.handleClick}> | |||
<ElementType {...rest} className={classes} | |||
onClick={this.handleClick} onChange={this.handleClick} |
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.
Still need the line break here 😉
- onClick={this.handleClick} onChange={this.handleClick}
+ onClick={this.handleClick}
+ onChange={this.handleClick}
Sounds good @levithomason. I'll get to this in a bit. |
@levithomason Just pushed a fix that takes care of this issue, I believe. Let me know if we need anything else. |
Changes look good, we just need some tests for this and we can merge 👍 |
@levithomason I should also add |
@levithomason without adding any test cases, this one seems to fail. are we not exposing the prop properly at the user level? |
@layershifter tests still fail locally. |
Yep, I see. Will back there tomorrow 😴 |
@layershifter pushed a new commit, it could be a potential fix. Let me know if it looks ok |
This component looks good conformance as far as conformance tests go. We now just need a test that asserts that: it('sets focuses the input onMouseDown', () => { ... }) |
What exactly should be checked in this test? I was basing my implementation on the |
The |
@levithomason I've made some cleanups and added test |
💥 thanks much! |
Released in |
Fixes #1335