-
Notifications
You must be signed in to change notification settings - Fork 337
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
Add onKeyDown to TextField and TextArea #303
Merged
jennyscript
merged 4 commits into
pinterest:master
from
jennyscript:add-keydown-textarea
Aug 20, 2018
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fe93cab
Add onKeyDown to TextField and TextArea
jennyscript 96e3ca2
Flow type elements in event handlers instead of instanceof checks
jennyscript 8308a07
Merge branch 'master' into add-keydown-textarea
christianvuerings 4d83201
Merge branch 'master' into add-keydown-textarea
jennyscript File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
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
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 |
---|---|---|
|
@@ -21,9 +21,22 @@ type Props = {| | |
id: string, | ||
idealErrorDirection?: 'up' | 'right' | 'down' | 'left' /* default: right */, | ||
name?: string, | ||
onBlur?: ({ event: SyntheticFocusEvent<>, value: string }) => void, | ||
onChange: ({ event: SyntheticInputEvent<>, value: string }) => void, | ||
onFocus?: ({ event: SyntheticFocusEvent<>, value: string }) => void, | ||
onBlur?: ({ | ||
event: SyntheticFocusEvent<HTMLTextAreaElement>, | ||
value: string, | ||
}) => void, | ||
onChange: ({ | ||
event: SyntheticInputEvent<HTMLTextAreaElement>, | ||
value: string, | ||
}) => void, | ||
onFocus?: ({ | ||
event: SyntheticFocusEvent<HTMLTextAreaElement>, | ||
value: string, | ||
}) => void, | ||
onKeyDown?: ({ | ||
event: SyntheticKeyboardEvent<HTMLTextAreaElement>, | ||
value: string, | ||
}) => void, | ||
placeholder?: string, | ||
rows?: number /* default: 3 */, | ||
value?: string, | ||
|
@@ -40,6 +53,7 @@ export default class TextArea extends React.Component<Props, State> { | |
onBlur: PropTypes.func, | ||
onChange: PropTypes.func.isRequired, | ||
onFocus: PropTypes.func, | ||
onKeyDown: PropTypes.func, | ||
placeholder: PropTypes.string, | ||
rows: PropTypes.number, | ||
value: PropTypes.string, | ||
|
@@ -68,39 +82,46 @@ export default class TextArea extends React.Component<Props, State> { | |
return null; | ||
} | ||
|
||
handleChange = (event: SyntheticInputEvent<>) => { | ||
if (event.target instanceof HTMLTextAreaElement) { | ||
this.props.onChange({ | ||
event, | ||
value: event.target.value, | ||
}); | ||
handleChange = (event: SyntheticInputEvent<HTMLTextAreaElement>) => { | ||
this.props.onChange({ | ||
event, | ||
value: event.currentTarget.value, | ||
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. are we sure this is the same, |
||
}); | ||
|
||
if (this.props.errorMessage) { | ||
this.setState({ errorIsOpen: true }); | ||
} | ||
if (this.props.errorMessage) { | ||
this.setState({ errorIsOpen: true }); | ||
} | ||
}; | ||
|
||
handleBlur = (event: SyntheticFocusEvent<>) => { | ||
handleBlur = (event: SyntheticFocusEvent<HTMLTextAreaElement>) => { | ||
if (this.props.errorMessage) { | ||
this.setState({ errorIsOpen: false }); | ||
} | ||
if (event.target instanceof HTMLTextAreaElement && this.props.onBlur) { | ||
if (this.props.onBlur) { | ||
this.props.onBlur({ | ||
event, | ||
value: event.target.value, | ||
value: event.currentTarget.value, | ||
}); | ||
} | ||
}; | ||
|
||
handleFocus = (event: SyntheticFocusEvent<>) => { | ||
handleFocus = (event: SyntheticFocusEvent<HTMLTextAreaElement>) => { | ||
if (this.props.errorMessage) { | ||
this.setState({ errorIsOpen: true }); | ||
} | ||
if (event.target instanceof HTMLTextAreaElement && this.props.onFocus) { | ||
if (this.props.onFocus) { | ||
this.props.onFocus({ | ||
event, | ||
value: event.target.value, | ||
value: event.currentTarget.value, | ||
}); | ||
} | ||
}; | ||
|
||
handleKeyDown = (event: SyntheticKeyboardEvent<HTMLTextAreaElement>) => { | ||
if (this.props.onKeyDown) { | ||
this.props.onKeyDown({ | ||
event, | ||
value: event.currentTarget.value, | ||
}); | ||
} | ||
}; | ||
|
@@ -140,6 +161,7 @@ export default class TextArea extends React.Component<Props, State> { | |
onBlur={this.handleBlur} | ||
onChange={this.handleChange} | ||
onFocus={this.handleFocus} | ||
onKeyDown={this.handleKeyDown} | ||
placeholder={placeholder} | ||
ref={c => { | ||
this.textarea = c; | ||
|
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
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
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
Oops, something went wrong.
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.
These are going to cause Flow errors when bumping in pinboard - prepare yourselves, winter is coming