-
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
Merged
levithomason
merged 9 commits into
Semantic-Org:master
from
tarang9211:fix/checkbox-onfocus
Mar 24, 2017
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e1e4544
fix(Checkbox): added onFocus prop
tarang9211 bee7c99
fix(Checkbox): added handleFocus callback to be triggered
tarang9211 17a9f4c
fix(Checkbox): added onMouseDown event to invoke focus event
tarang9211 5a41626
fix: call user onMouseDown prop when onMouseDown event is trigger
tarang9211 d83b46a
style: added onMouseDown to component propTypes
tarang9211 7a89fa5
Update Checkbox.js
layershifter c81b2a8
test: potential fix for checkbox test
tarang9211 f8672e9
Merge branch 'master' of https://github.com/Semantic-Org/Semantic-UI-…
1b69037
fix(Checkbox): onFocus and onBlur events
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -149,6 +149,10 @@ export default class Checkbox extends Component { | |
} | ||
} | ||
|
||
handleMouseDown = (e) => { | ||
_.invoke('focus', this.checkboxRef) | ||
} | ||
|
||
// Note: You can't directly set the indeterminate prop on the input, so we | ||
// need to maintain a ref to the input and set it manually whenever the | ||
// component updates. | ||
|
@@ -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 commentThe 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 commentThe 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} |
||
onMouseDown={this.handleMouseDown} | ||
> | ||
<input | ||
checked={checked} | ||
className='hidden' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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: