-
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): focus should be obtained on mouseDown #1762
Conversation
@@ -1,5 +1,5 @@ | |||
import cx from 'classnames' | |||
import _ from 'lodash/fp' | |||
import _ from 'lodash' |
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.
@levithomason I removed usage of lodash/fp
because I don't understand how I can make this in FP style:
_.invoke(this.props, 'onMouseDown', e, { ...this.props, checked: !!checked, indeterminate: !!indeterminate })
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.
No worries, this works 👍
98cf03f
to
0ab6811
Compare
Codecov Report
@@ Coverage Diff @@
## master #1762 +/- ##
==========================================
+ Coverage 99.75% 99.75% +<.01%
==========================================
Files 142 142
Lines 2459 2466 +7
==========================================
+ Hits 2453 2460 +7
Misses 6 6
Continue to review full report at Codecov.
|
Order of eventsThe order of events as fired by the browser are: new_comment_field.addEventListener('click', () => console.log('click'))
new_comment_field.addEventListener('mousedown', () => console.log('mousedown'))
new_comment_field.addEventListener('mouseup', () => console.log('mouseup'))
new_comment_field.addEventListener('focus', () => console.log('focus')) A click, long press, and release logs this: onBlurThat said, our bug is that the This extra blur event is a side effect of calling Update to this PR // handleClick() {
// ..snip
_.invoke(this.props, 'onChange', e, { ...this.props, checked: !checked, indeterminate: false })
this.trySetState({ checked: !checked, indeterminate: false })
- _.invoke(this.inputRef, 'focus')
}
handleMouseDown = e => {
debug('handleMouseDown()')
const { checked, indeterminate } = this.state
_.invoke(this.props, 'onMouseDown', e, { ...this.props, checked: !!checked, indeterminate: !!indeterminate })
+ _.invoke(this.inputRef, 'focus')
+ e.preventDefault()
} The testThis results in the correct behavior as well as the correct order of events fired: Give that a try and let me know your thoughts. |
@levithomason Thanks for a detailed reply. You're right there, seems that SUI implements focus incorrectly, it triggers |
0ab6811
to
10532de
Compare
Thanks for the confirmation and second round. |
Released in |
Finally fixes #1335.
We added focus capture in #1361, but we added it into theonMouseDown
handler while it should be insideonClick
handler.SUI behavior